Simple question: How do I create a concated variable name. Is this possible?:
local currentDoorNumber = 32
local "door" .. currentDoorNumber = "isClosed"
Simple question: How do I create a concated variable name. Is this possible?:
local currentDoorNumber = 32
local "door" .. currentDoorNumber = "isClosed"
No, that isn’t possible (MIGHT be possible with getfenv
and setfenv
, but I never used those functions before), and there shouldn’t be a reason to ever need it. What are you trying to achieve by doing this?
Theres probably a simpler solution as to what your trying to do
I am trying to save multiple variables in a for loop, each getting assigned to a specific iteration, giving their status.
I am trying to set the name of the variable to "door32"
by concating "door"
and currentDoorNumber
Well I can understand what you are trying to do, I dont believe its possible to concatenate variable names.
And I believe what you want to do is check the doors and check if they are closed or not, for this you can do a dictionary with each door name like this:
local doors = {}
doors["door1"] = false --Closed
doors["door2"] = true --Open
You could just use a table to store all those values, like this:
for index, Door in pairs(Doors) do
DoorOpenedInfo[index] = "isClosed"
end
I think you didnt understand whats hes saying, he wants to name a VARIABLE a concatenated string.
I dont believe thats possible.
Yeah, it’s object orientation time!
You are right, it is not possible to name a variable a string, however he could use a value instance
Thats not actually a object orientation but you can use it to make it more interesting to use.
local ["Apple" .. " Sauce"] = 64