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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -