• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

[Solved] [Lua] Running a function with a timer

Status
Not open for further replies.
Level 9
Joined
Jul 30, 2018
Messages
445
Hey!

I have another Lua related question. Why does this work:
Lua:
function TestTimer()
    TimerStart(CreateTimer(), 1, true, function()
        print("Timer Message")
    end)
end
But not this:
Lua:
function TimerMessage()
    print("Timer Message")
end

function TestTimer()
    TimerStart(CreateTimer(), 1, true, TimerMessage())
end

The latter one will run once, but not periodically.
 
Because currently you call the function TimerMessage() when you are starting the Timer, the returned value is then taken as callback for TimerStart, in the current code that is nothing (nil).
Probably you only want to give the timer a reference to that function. Remove "()" inside TimerStart, then TimerMessage is not called and the function is given to the timer.
 
Status
Not open for further replies.
Top