For example:
local var1 = false
local var2 = false
}
Here I want to make var 1 true on first click then var2 true and var1 false on 2nd click
For example:
local var1 = false
local var2 = false
}
Here I want to make var 1 true on first click then var2 true and var1 false on 2nd click
I din’t quite get what you meant, but if you want to scroll through all the variables in a table, just use for i,v in pairs.
local Vars = {var1=false,var2=false}
local Index = 1
UI.MouseButton1Down:Connect(function()
Vars['var'..Index] = true
Index += 1
end
You could use this approach of using index, index increments as you click thus you can procedurally turn the values to true.
Similar to the previous message:
local Vars = {var1=false,var2=false}
local Index = 1
UI.MouseButton1Down:Connect(function()
for _, var in pairs(Vars) do
var = false
end
Vars['var'..Index] = true
Index += 1
local Count = 0
for _, v in pairs(Vars) do
Count += 1
end
if Index > Count then
Index = 1
end
end
The person above just forgot to clear all before setting a new value. I also made it go back to the start when it reaches the end
In your method #Vars won’t work as your are attempting to get the length of a dictionary therefore it would return 0
I don’t think he mentioned about clearing the table,
OP did mention the clearing of it:
Here I want to make var 1 true on first click then var2 true and var1 false on 2nd click
However in your method
#Varswon’t work
I have never had any issue using # on a dictionary. Ill double check but im pretty sure it works
My bad I read it wrong.
# won’t return the length for dictionaries, it would work for arrays.
Fixed the original post, and my reply to you
local Vars = {var1=false,var2=false}
local Index = 1
UI.MouseButton1Down:Connect(function()
for _, var in pairs(Vars) do
var = false
end
Vars['var'..Index] = true
Index += 1
if Vars['var'..Index] == nil then
Index = 1
end
end
Not mandatory, but you could avoid the second loop and just check whether the next index is nil and not false
I couldn’t understand what the 7th line mean can u explain it??
local var1 = false
local var2 = false
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
var1 = not var1
var2 = if var1 then false else true
end
end)
If they are supposed to be in array, just account for that
The Vars dictionary has the keys var1 , var2 and the Index is an number so to get the var1 value from the dictionary. I would have to do Vars.var1 or Vars['var1'] here as Im using Index I have to concatenate the Index and “var” "var"..index would be var1 if the Index is one. And I use that to index the key in the table
And what does the last conditional statement mean??