Maintain Focus with two textbox and button using Brightscript - focus

I created a one Login Form in the bright script. It's following
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
TextBox 1 ' Here the focus is active I set by default in TextBox field active = true
TextBox 2 ' Here the press down key to active true
Button 1 ' Here again press down key to focus true
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Here, I maintain the 3 Items using 3 different key. Now I want to maintain the single key for all 3 items using the down key. Anyone idea to How to maintain Focus using Brightscript.
I used the one function for key handling It's here
function onKeyEvent(key as String, press as Boolean) as Boolean
.................
end function
Now, I maintained the key like
I set TextBox Focus active in ByDefault to XML File.Now I apply Logic to below.
First item focus set on XML file by default.
if key = "down" then
'Here Second item focus
m.keypass.active = true ' Here work successfully First time
if key = "down" and m.keypass.active = true and m.btnsub.active = false then
'Here not maintain successfully its directly call here I press the down key.
m.keypass.active = false
m.btnsub.active = true 'Here third item focus is not maintained
end if
end if
I first-time press the down key It's working fine But its second time How handling the Focus. I used the same thing in Up key.
Here I am using "and" then the issue will happen is there any idea.
Pls, Check Here's an image really what I want to do.
Edited Post:
I handle with up and down key with below code. It's working But, Its only work in a single time.
if key = "up" or key = "down"
if key = "down"
?"here down key"
if m.keypass.id = "instructpass" and m.keypass.active = true
? "down key if part"
m.btngrp.setFocus(true)
m.keypass.active = false
handled = true
else if m.keyid.id = "instructid" and m.keyid.active = true
?" down key else part"
m.keypass.active = true
m.keyid.active = false
handled = true
else if m.btngrp.buttonSelected = 0
m.keyid.active = true
m.btngrp.setFocus(false)
handled = true
end if
handled = true
else if key = "up"
? "here up key"
if m.keypass.active = true
?"up key if part"
m.keyid.active = true
m.keypass.active = false
handled = true
else if m.keyid.active = true
?"id key"
m.btngrp.setFocus(true)
m.btngrp.focusButton = 1
m.keyid.active = false
handled = true
else if m.btngrp.focusButton = 0 and m.btngrp.buttonSelected = 0
?"up key else part"
m.keypass.active = true
m.keypass.setFocus(true)
m.btngrp.setFocus(false)
handled = true
end if
handled = true
end if
handled = true
end if
Thank you.

Check here.
You should use .setFocus(true) and .hasFocus(), which are available to most renderable nodes such as TextEditBox and Button.
E.g.
if key = "down" then
if textBox1.hasFocus() then
textBox2.setFocus(true)
elseif textBox2.hasFocus() then
button.setFocus(true)
end if
end if
if key = "up" then
if button.hasFocus() then
textBox2.setFocus(true)
elseif textBox2.hasFocus() then
textBox1.setFocus(true)
end if
end if

Related

how do i fix ')' (to close '(' at line 38), got '.'

for i, v in pairs(Buttons:GetChildren()) do
local NewItem = BoughtItems:FindFirstChild(v.Item.value)
if NewItem ~= nil then
Items[NewItem.Name] = NewItem:Clone()
NewItem:Destroy()
else
v.ButtonPart.Transparency = 1
v.ButtonPart.CanCollide = false
v.ButtonPart.BillBoardGui.Frame.Visible = false
end
if v:FindFirstChild("Dependency") then
coroutine.resume(coroutine.create(function(
v.ButtonPart.Transparency = 1
v.ButtonPart.CanCollide = false
v.ButtonPart.BillBoardGui.Frame.Visible = false
if BoughtItems:WaitForChild(v.Dependency.Value, 100000)then
v.ButtonPart.Transparency = 0
v.ButtonPart.CanCollide = true
v.ButtonPart.BillBoardGui.Frame.Visible = true
end
end))
end
v.ButtonPart.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid")then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Values.OwnerValue.Value == Player then
if v.ButtonPart.CanCollide == true and v.ButtonPart.Transparency == 0 then
if Player:WaitForChild("leaderstats").Cash.Value >= v.Price.Value then
Player.leaderstats.Cash.Value -= v.Price.Value
Items[v.Item.Value].Parent = BoughtItems
v:Destroy()
end
end
end
end
end)
end
how do i fix this the header is the problem i dont knw what it means so is there a fix to it for my tycoon if anyone knows pls comment (heres some random stuff since my post is mostly code) A brief Introduction to Copypasta. Copypasta means to copy a text or a part of the text from an existing manuscript and inclusion of that very text in an under-process manuscript by pasting. At present, the societies are going to be expanded with an enormous pattern.
Parenthesis always come in pairs. The error message already strongly suggests that you are missing a closing parenthesis for an opening one in line 38.
1 2 3
coroutine.resume(coroutine.create(function(
v.ButtonPart.Transparency = 1
v.ButtonPart.CanCollide = false
v.ButtonPart.BillBoardGui.Frame.Visible = false
if BoughtItems:WaitForChild(v.Dependency.Value, 100000)then
v.ButtonPart.Transparency = 0
v.ButtonPart.CanCollide = true
v.ButtonPart.BillBoardGui.Frame.Visible = true
end
end)) <--- one is missing
1 2
Use a text editor that autocompletes pairs or even better one that hightlights pairs in matching colors to avoid errors like this.

attempt to compare string and number lua

script.Parent.Yes.MouseButton1Click:connect(function()
if game.Players.LocalPlayer.leaderstats.Stage.Value < 20 and db then
db = false
script.Parent.Question.Text = "YOU NEED ATLEAST 20 STAGES TO REBIRTH!"
wait(3)
script.Parent.Visible = false
open = false
db = true
elseif db then
game.ReplicatedStorage.Rebirth:FireServer()
script.Parent.Visible = false
open = false
end
end)
why is this showing an error on line 2 saying attempt to compare string and number?
That means game.Players.LocalPlayer.leaderstats.Stage.Value is a string. I don't know how leaderstats work but I think you've made it a string accidentally instead of a number.

Progress forwards and backwards through table

first time here on Stack Overflow but definitely have found a lot of useful information here!
Currently I'm trying to figure out how to select the next item, or previous item in a table based on the current selection.
My current table is as follows:
maleSkins = { 7,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,32,33,34,35,
36,37,43,44,45,46,47,48,49,51,52,57,58,59,60,61,66,67,72,73,80,82,83,
84,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
112,113,114,115,116,117,118,120,121,122,123,124,125,126,127,128,132,
133,134,135,136,137,142,143,144,146,147,153,154,156,159,160,161,162,
168,170,173,174,175,176,177,179,180,181,182,183,184,185,186,187,188,
189,200,202,203,204,206,210,212,213,217,220,221,222,223,227,228,229,
230,234,235,236,239,240,241,242,247,248,249,250,252,254,258,259,260,261,262 }
femaleSkins = { 9,10,11,12,13,31,38,39,40,41,53,54,55,56,69,76,77,88,89,90,91,92,
93,129,130,131,138,139,140,141,145,148,151,152,157,190,191,192,193,195,
196,197,198,199,201,207,211,214,215,216,218,219,224,225,226,232,233,237,238,243,244,245,246,251,256,257 }
The default selection is "7" in the maleSkins table, and I will use the femaleSkins table when they choose "female" for their gender.
Currently my function call looks like this
function selSkin(button,state)
if button ~= "left" and state ~= "up" then
return
end
if source == createChar.maleButt then
femaleSkin = false
maleSkin = true
elseif source == createChar.femaleButt then
maleSkin = false
femaleSkin = true
end
if source == createChar.nextSkin then
if maleSkin == true then
newModel = table.concat(maleSkins,)
elseif femaleSkin == true then
end
elseif source == createChar.prevSkin then
if maleSkin == true then
elseif femaleSkin == true then
end
end
end
So, inside the "createChar.nextSkin" and "createChar.prevSkin" is where I'm trying to sort through the table based on the current skin, but I'm unsure of how to proceed.
I would love if someone could give me the building blocks to do this, and I will build the rest myself!
(Side note: Predefined variables I will be using to make this happen)
maleSkin = true
femaleSkin = true
curSkin = 7
newModel = nil
First of all welcome to stack overflow :)
A small thing I noticed: you have two variables to store if the character is male or female. This allows for 4 combinations, 2 of which make no sense. You could just as well only use one variable, say, maleSkin and when it's false, then you use the female skin instead. Alternatively, you could just do skinType = 'male' and skinType = 'female' (Lua interns strings, so this is just as fast as comparing integers)
now, unless you plan to have a few millions of skins or more, you can just iterate through the table to find the current skin and then use the previous one.
function skinOffset(skin, skinList, offset)
for i,current_skin in ipairs(skinList) do
if current_skin == skin then
return skinList[i + offset]
else
end
end
Now, to get the next skin you can do skinOffset(curSkin, maleSkins, 1) and for the previous one skinOffset(curSkin, femaleSkins, -1).
Additionally save the table index in a global var.
There are several ways, for instance skinIndex = 1, your code could look like this:
if source == createChar.nextSkin then
newModel = maleSkin and maleSkins[skinIndex + 1] or femaleSkins[skinIndex + 1]
elseif source == createChar.prevSkin then
newModel = maleSkin and maleSkins[skinIndex - 1] or femaleSkins[skinIndex - 1]
end
But you have to beware of skinIndex < 1 or > #maleSkins/#femaleSkins

Cloning+Dragging model when button is click ROBLOX [LUA]?

So I thought of having this for so long, I just don't know where to start. I am new to this language and I keep learning, but kind of hard for me. But I have built my very own custom character which took 2 weeks for me. Anyway, For my question. An example is if I have a button and I click it, a model will be clone and I can drag that model and put it anywhere nearby. What possible method I can use to achieve this?
First things first, I suggest for any future questions, you head over to https://scriptinghelpers.org/
now, on to your question, for cloning the model, you should use mouse.Target.Parent:Clone() or the GetTopParent(mouse.Target) function in my function library (which you can get here; http://www.roblox.com/item.aspx?id=244244638)
then deposit the model into workspace and MakeJoints()
the next step is to move the model, this can be tricky, but the simplest method is model:MoveTo(mouse.Hit.p) on mouse.Moved (but that's a little buggy)
Another method for movement would be to use the Handles class, but I'm not really familiar with it, so you'd have to figure that one out on your own.
To make the first method less buggy, I'd suggest something along the lines of
model:MoveTo(mouse.Hit.p.X, mouse.Target.Position.Y + (model:GetExtentsSize().Y / 2), mouse.Hit.p.Z)
but you'd have to set up the mouse to ignore the model, which I can't really help with.
A really good place to start is to search the free models in Studio Toolbox for a 'Dragger Tool' or 'Model Dragger Tool' and then use the script inside to get started creating your own. I have learned to create my own custom draggers by doing this and it is way easier than you may think at first. Once you find a good dragger tool to borrow code from, if you need to enhance it, you can find the dragger api in the Roblox Wiki to help you further customize it to your specific needs.
http://wiki.roblox.com/index.php?title=API:Class/Dragger
EDIT: So here's the first dragger script that showed when I searched. It will drag models and parts but you will have to edit it to meet your requirements using the dragger api. Create a Tool in player.BackPack then create a LocalScript inside the Tool then copy and paste the code below into the LocalScript, and that will get you started.
local Tool = script.Parent
enabled = true
local origTexture = Tool.TextureId
game:GetService("ContentProvider"):Preload("rbxasset://icons/freemove_sel.png")
local selectionBox
local currentSelection
local currentSelectionColors = {}
local selectionLasso
local inGui = false
local inPalette = false
local lockTime = 0
function canSelectObject(part)
return part and not (part.Locked) and (part.Position - script.Parent.Parent.Head.Position).Magnitude < 60
end
function findModel(part)
while part ~= nil do
if part.className == "Model" then
return part
end
part = part.Parent
end
return nil
end
function startDrag(mousePart, hitPoint, collection)
dragger = Instance.new("Dragger")
pcall(function() dragger:MouseDown(mousePart, hitPoint, collection) end)
end
function collectBaseParts(object, collection)
if object:IsA("BasePart") then
collection[#collection+1] = object
end
for index,child in pairs(object:GetChildren()) do
collectBaseParts(child, collection)
end
end
function onMouseDown(mouse)
mouse.Icon ="rbxasset://textures\\GrabRotateCursor.png"
local part = mouse.Target
if canSelectObject(part) then
local hitPoint = mouse.Hit:toObjectSpace(part.CFrame).p
if trySelection(part) then
local instances = {}
collectBaseParts(currentSelection, instances)
startDrag(part, hitPoint, instances)
return
end
end
--Clear the selection if we weren't able to lock succesfullu
onMouseUp(mouse)
end
function onMouseUp(mouse)
mouse.Icon ="rbxasset://textures\\GrabCursor.png"
if dragger ~= nil then
pcall(function() dragger:MouseUp() end)
dragger = nil
end
end
function trySelection(part)
if canSelectObject(part) then
selectionLasso.Part = part
local model = findModel(part)
if model then
return setSelection(model)
else
return setSelection(part)
end
else
clearSelection()
return false
end
end
function onKeyDown(key)
if dragger ~= nil then
if key == 'R' or key == 'r' then
dragger:AxisRotate(Enum.Axis.Y)
elseif key == 'T' or key == 't' then
dragger:AxisRotate(Enum.Axis.Z)
end
end
end
local alreadyMoving
function onMouseMove(mouse)
if alreadyMoving then
return
end
alreadyMoving = true
if dragger ~= nil then
--Maintain the lock
if time() - lockTime > 3 then
Instance.Lock(currentSelection)
lockTime = time()
end
--Then drag
pcall(function() dragger:MouseMove(mouse.UnitRay) end)
else
trySelection(mouse.Target)
end
alreadyMoving = false
end
function saveSelectionColor(instance)
if instance:IsA("BasePart") then
currentSelectionColors[instance] = instance.BrickColor
if instance.BrickColor == BrickColor.Blue() then
instance.BrickColor = BrickColor.new("Deep blue")
else
instance.BrickColor = BrickColor.Blue()
end
end
local children = instance:GetChildren()
if children then
for pos, child in pairs(children) do
saveSelectionColor(child)
end
end
end
function setSelection(partOrModel)
if partOrModel ~= currentSelection then
clearSelection()
if Instance.Lock(partOrModel) then
lockTime = time()
currentSelection = partOrModel
saveSelectionColor(currentSelection)
selectionBox.Adornee = currentSelection
return true
end
else
if currentSelection ~= nil then
if time() - lockTime > 2 then
--Maintain the lock
if not(Instance.Lock(currentSelection)) then
--we lost the lock
clearSelection()
return false
else
lockTime = time()
return true
end
else
return true
end
end
end
return false
end
function clearSelection()
if currentSelection ~= nil then
for part, color in pairs(currentSelectionColors) do
part.BrickColor = color
end
selectionBox.Adornee = nil
Instance.Unlock(currentSelection)
end
currentSelectionColors = {}
currentSelection = nil
selectionLasso.Part = nil
selectionBox.Adornee = nil
end
function onEquippedLocal(mouse)
Tool.TextureId = "rbxasset://icons/freemove_sel.png"
local character = script.Parent.Parent
local player = game.Players:GetPlayerFromCharacter(character)
inGui = false
inPalette = false
mouse.Icon ="rbxasset://textures\\GrabCursor.png"
mouse.Button1Down:connect(function() onMouseDown(mouse) end)
mouse.Button1Up:connect(function() onMouseUp(mouse) end)
mouse.Move:connect(function() onMouseMove(mouse) end)
mouse.KeyDown:connect(function(string) onKeyDown(string) end)
selectionBox = Instance.new("SelectionBox")
selectionBox.Name = "Model Delete Selection"
selectionBox.Color = BrickColor.Blue()
selectionBox.Adornee = nil
selectionBox.Parent = player.PlayerGui
selectionLasso = Instance.new("SelectionPartLasso")
selectionLasso.Name = "Model Drag Lasso"
selectionLasso.Humanoid = character.Humanoid
selectionLasso.archivable = false
selectionLasso.Visible = true
selectionLasso.Parent = game.workspace
selectionLasso.Color = BrickColor.Blue()
alreadyMoving = false
end
function onUnequippedLocal()
Tool.TextureId = origTexture
clearSelection()
selectionBox:Remove()
selectionLasso:Remove()
end
Tool.Equipped:connect(onEquippedLocal)
Tool.Unequipped:connect(onUnequippedLocal)

lua - checking for duplicate data in a string

I have the following string data that I receive as input:
"route1,1234,1,no~,,route2,1234,1,no~,"
It represents two "records" of data... where each record has 4 fields.
I've built code to parse this string into it's individual columns / fields.
But the part that isn't working is when I test to see if I have any duplicates in field 2. Field 2 is the one that currently has "1234" as the value.
Here's the code:
function string:split(delimiter)
local result = { }
local from = 1
local delim_from, delim_to = string.find( self, delimiter, from )
while delim_from do
table.insert( result, string.sub( self, from , delim_from-1 ) )
from = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from )
end
table.insert( result, string.sub( self, from ) )
return result
end
local check_for_duplicate_entries = function(route_data)
local route
local route_detail = {}
local result =true
local errtxt
local duplicate = false
print("received :" ..route_data)
route = string.gsub(route_data, "~,,", "~")
route = route:sub(1,string.len(route)-2)
print("route :" ..route)
-- break up in to an array
route = string.split(route,"~")
for key, value in pairs(route) do
route_detail[key] = string.split(value,",")
end
local list_of_second_column_only = {}
for key,value in pairs(route_detail) do
local temp = value[2]
print(temp .. " - is the value I'm checking for")
if list_of_second_column_only[temp] == nil then
print("i dont think it exists")
list_of_second_column_only[key] = value[2]
print(list_of_second_column_only[key])
else
--found a duplicate.
return true
end
end
return false
end
print(check_for_duplicate_entries("route1,1234,1,no~,,route2,1234,1,no~,"))
I think where I'm going wrong is the test:
if list_of_second_column_only[temp] == nil then
I think I'm checking for key with the value temp instead of a value with the value that temp contains. But I don't know how to fix the syntax.
Also, I'm wondering if there's a more efficient way to do this.
The number of "records" i receive as input is dynamic / unknown, as is the value of the second column in each record.
Thanks.
EDIT 1
The post I was trying to use as a reference is: Search for an item in a Lua list
In the answer, they show how to test for a record in the table by value, instead of looping through the entire table...
if items["orange"] then
-- do something
end
I was playing around to try and do something similar...
This should be a bit more efficient with only one table creation and less regex matching.
The match does require that you're only interested in dups in the second field.
local function check_for_duplicate_entries(route_data)
assert(type(route_data)=="string")
local field_set = {}
for route in route_data:gmatch"([^~]*)~,?,?" do
local field = route:match",([^,]*)"
if field_set[field] then
return true
else
field_set[field] = true
end
end
return false
end
Try this. It's doing the check on the value of the second field.
I haven't looked at the efficiency.
if list_of_second_column_only[value[2]] == nil then
print("i dont think it exists")
list_of_second_column_only[value[2]] = true
print(list_of_second_column_only[value[2]])
else
--found a duplicate.
return true
end

Resources