How to increment a variable name by 1 in Lua, and then set that as the variable name? -
my current code is:
obj1 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "tree"} obj2 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "tree"} obj3 = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "tree"}
and on. since same thing, i'd able generate variable can increment name one, , use loop create lot of them. there way can in lua? thanks!
you can use table hold objects , add them using loop.
local objects = {} --> create 20 objects i=1, 20 objects[i] = object:new{x = math.random(1,92), y = math.random(1,92), roomx = 0, roomy = 0, symbol = "t", name = "tree"} end
Comments
Post a Comment