How to store data about enemy attack, health, attack speed, and movement speed?

Here is a skeleton class you can extend

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

You can also reference them individually

bots[25]:start() bots[71]:stop()

  

I was referring to the car example. But the post above does a great job of showing how to use it.

Rob

@Sphere Game Studios, Thanks for the template! I am trying it out.

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. 

I am trying to set a color, but it does not work.

--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

This is what I get printed (but 10 more times):

 1 1 table: 0x7ff73bf67bc0 2 2 table: 0x7ff73bf67d10 3 3 table: 0x7ff73bf67f80 4 4 table: 0x7ff73bf68230 5 5 table: 0x7ff73bf68350 6 6 table: 0x7ff7397a8040 7 7 table: 0x7ff7397a8340 8 8 table: 0x7ff7397a85d0 9 9 table: 0x7ff7397a8860 10 10 table: 0x7ff7397a8a90

How do I fix this? 

Set the colour in new() like this

aNewBot:setFillColor( color[1], color[2], color[3], color[4] or 1 )

How could I set an image for the bots? I tried this:

function bot:new(x, y, height, width, image) local newBot = {} newBot.x, newBot.y, x,y newBot.anchorX, newBot.anchorY = 1,0 newBot.height, newBot.width = height, width) newBot = display.newImage(image) --declare functions for bot newBot.start = start newBot.stop = stop return setmetatable( newBot, bot\_mt ) end

But it only appeared once at the the coordinate 0,0.

Look, I am busy and can’t write your stuff for you.  You are going to have to figure some stuff out for yourself.

But briefly you cannot say

newBot = display.newImage(image)

your would say

newBot.image = display.newImage(image) newBot.image.x, newBot.image.y = x, y

Thank you, and I apologize for using up your time.  :frowning: