Classes and Timers

enemy = {}

function enemy:new(x,y)

Square = display.newRoundedRect( 0, 0, 80, 80,15)

  Square.x = x

  Square.y = y

function Square:change_colour(event)

local red = math.random()

local blue = math.random()

local green = math.random()

self:setFillColor( red,blue,green )

end

timer.performWidthDelay(1000, Square.Line)

return Square

end

return enemy


How would I implement a timer for the function “Line” to work within a class?

First off I would make enemy table and square local just for performance

If you want to call the square.line function you have to declare it before you call it.

–rest of code

function Square.Line()

print(“hello”)

end

timer.performWidthDelay(1000, Square.Line)

–rest of code

Also recommend camel casing which in coding is the first word is lower cased then the words that follow it are uppercase.
Like: helloWorldToday

First off I would make enemy table and square local just for performance

If you want to call the square.line function you have to declare it before you call it.

–rest of code

function Square.Line()

print(“hello”)

end

timer.performWidthDelay(1000, Square.Line)

–rest of code

Also recommend camel casing which in coding is the first word is lower cased then the words that follow it are uppercase.
Like: helloWorldToday