requirement -
I want a function to be called after 10sec of the game start and it should be called every second repeatedly.
I tried following way, but its not working…
local function drawRectangleWrapper()
print ("Started wrapper after 10 seconds F militent ")
local function drawRectangle ()
print ("Drawing Rectangle… ")
end
timer.performWithDelay( 1000, drawRectangle(), 0 )
remove the () from the function you pass to performWithDelay. it should be:
local function drawRectangleWrapper()
print ("Started wrapper after 10 seconds F militent ")
local function drawRectangle ()
print ("Drawing Rectangle.. ")
end
timer.performWithDelay( 1000, drawRectangle, 0 )
end
timer.performWithDelay( 10000, drawRectangleWrapper, 1 )
When you put the extra “()” it tells lua to execute the function and pass it’s return value to performWithDelay. Your functions both return nothing (=nil) so perform with delay doesn’t call anything.
Instead what you want is to pass the actual pointer of the function to performWithDelay so later it can call it…
This is a common typo…
PS, when submitting a code snippet it’s best to wrap it withing a <code> tag so it gets a fixed width font and syntax coloring… much easier to read your code and help out
[import]uid: 80469 topic_id: 30536 reply_id: 122339[/import]
remove the () from the function you pass to performWithDelay. it should be:
local function drawRectangleWrapper()
print ("Started wrapper after 10 seconds F militent ")
local function drawRectangle ()
print ("Drawing Rectangle.. ")
end
timer.performWithDelay( 1000, drawRectangle, 0 )
end
timer.performWithDelay( 10000, drawRectangleWrapper, 1 )
When you put the extra “()” it tells lua to execute the function and pass it’s return value to performWithDelay. Your functions both return nothing (=nil) so perform with delay doesn’t call anything.
Instead what you want is to pass the actual pointer of the function to performWithDelay so later it can call it…
This is a common typo…
PS, when submitting a code snippet it’s best to wrap it withing a <code> tag so it gets a fixed width font and syntax coloring… much easier to read your code and help out
[import]uid: 80469 topic_id: 30536 reply_id: 122339[/import]