local bot = {} local bot\_mt = {\_\_index = bot} local function start(self) --do something with this bot end local function stop(self) --do something with this bot end function bot:new(x,y,...) local newBot = {} //set properties of bot based on parameters based newBot.x, newBot.y = x, y //declare functions for bot newBot.start = start newBot.stop = stop return setmetatable( newBot, bot\_mt ) end return bot
Now you can create multiple instances of bot - in this case we will spawn 100 of them
local bots = {} for i = 1, 100 do local aNewBot = bot:new(i,i) bots[#bots+1] = aNewBot end
Thank you so much for this template, I was able to print out all their x and y values. Now I will move on to more complex things, like printing atk or def.
--stats.lua local bot = {} local bot\_mt = {\_\_index = bot} local function start(self) --do something with this bot end local function stop(self) --do something with this bot end function bot:new(x, y, color, height, width) local newBot = {} newBot.x, newBot.y = x,y newBot.height, newBot.width, newBot.fill = height, width, color --declare functions for bot newBot.start = start newBot.stop = stop return setmetatable( newBot, bot\_mt ) end return bot --main.lua local bot = require "stats" local bots = {} for i = 1, 20 do local aNewBot = bot:new(i, i, {1,0,0,0.5}, 10, 10) bots[#bots+1] = aNewBot print(aNewBot.x, aNewBot.y) print(aNewBot.fill) end