This was my approach:
JASS:
function Trig_Untitled_Actions takes nothing returns nothing
local timer t = CreateTimer()
local real timeRemaining
call TimerStart(t, 60, false, null)
loop
set timeRemaining = TimerGetRemaining(t)
call DisplayTextToPlayer(Player(0),0,0,R2S(timeRemaining))
exitwhen timeRemaining <= 0
endloop
call PauseTimer(t)
call DestroyTimer(t)
set t = null
endfunction
//===========================================================================
function InitTrig_Untitled takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterTimerEvent(t, 0.00, false)
call TriggerAddAction( t, function Trig_Untitled_Actions )
set t = null
endfunction
EDIT: I think I see what I did wrong here, I need to pass a code to TimerStart and inside that function display the remaining time right?
Positive. Could be used to clean up the timer and assigments for example.
The loop you wrote above has no interval --> how should the exitwhen condition ever be fulfilled when you order the game permanently to do stuff, freezing everything. This would only work if wc3 was multithreaded but you would practically get an infinite/indeterminated amount of iterations in that loop. Now, wc3 has an execution limit, so it does not freeze the game in an infinite loop but cancels the code.
You can either put a TriggerSleepAction inside the loop or create another timer that fires every second or so. TriggerSleepActions has a lot of negatives, so would advise the latter.
You did not make any assigments here. You can leave this of course in case there is only one timer but if you want to have the expiration timer of any unit, you need to know somehow which timer belongs to which unit.
Assignment methods are the basic things you look into when starting to learning triggering. There are multiple though. The most direct and independent way would probably be the hashtable.
You init the hashtable somewhere with
InitHashtable
and save it in a global variable. Then you can use
Save<dataType>
to store data under a set of keys, read it out again by
Load<dataType>
, just take a look at the
API. To get a unique key you can use for the special unit, one usually takes the handle id of the unit with
GetHandleId
.
@Edit3: Better learn vJass to get familiar with structures.
@Edit5: Of course you can set a real every second and print it but the timer has the advantage that you can make clean itself up right way in the end and maybe do other stuff.