Problem with NewTimer() ?

vile

New Member
Reaction score
8
I doubt there is a problem with this system as many people use it, but i found an odd problem with it. Here are my base functions for it:

Code:
function NewTimer takes nothing returns timer
 if (TIMERS_N==0) then
     return CreateTimer()
 endif
 set TIMERS_N = TIMERS_N - 1
 return TIMERS[TIMERS_N]
endfunction

function ReleaseTimer takes timer t returns nothing
 call PauseTimer(t)
 set TIMERS[TIMERS_N] = t
 set TIMERS_N = TIMERS_N + 1
endfunction

Now, whenever i run the spell, the timers return in a weird way.

Code:
function SpawnMeteorites takes nothing returns nothing
    local unit u = gg_unit_Hblm_0270
    local player p = GetOwningPlayer(u)
    local unit m=null
    local integer i=var_MeteoritesSpawned
    local MeteoritesData d=MeteoritesStructs[i]
    if var_MeteoritesSpawned < var_MeteoritesMaxSpawned and GetUnitCurrentOrder(u) == 852503 then
        set var_MeteoritesSpawned=var_MeteoritesSpawned+1
        set m=d.m
        set d.m=null
        set d.ma=m
        set d.t=NewTimer()
        call TimerStart(d.t,2.5,false,function InitMeteorites)

So lets say d.t is started after 2.5 seconds.
MeteoritesStructs is an array that is declared in a previous function to use multiple data structs.

Now here's the problem:

Code:
function InitMeteorites takes nothing returns nothing
    local integer i=0
    local MeteoritesData d
    loop
        set d=MeteoritesStructs[i]
        exitwhen i>8 or GetExpiredTimer()==d.t
        set i=i+1
    endloop
    [B][I][U]call DebugMsg("reg"+I2S(i))[/U][/I][/B]

In the actual spell in-game, I see: reg0, reg1, reg2, and then I see it recycling.. going back to reg0 again. How the hell is that possible?

What makes me think its a NewTimer() problem, is that if I use CreateTimer(), it runs fine and doesnt get reset, its supposed to show reg* until reg8.

Any idea?
 

Tom Jones

N/A
Reaction score
437
How do you make it show reg1, reg2, reg3, etc., with that code? The debug message isn't inside the loop. As far as I can see, the function would allways display reg0.
 

vile

New Member
Reaction score
8
its not supposed to be inside the loop
the debug message is inside a timer expire function
i start multiple one time timers of 2.5 seconds
and then i search for the corresponding timer using the loop
then i display the number of timer.
works flawlessly when i use CreateTimer()
 

vile

New Member
Reaction score
8
I use d.destroy
MeteoritesStructs is eventually 0, yes, after a loop at the end of the trigger.
it happens initially, and not after the 2nd or 3rd usage of the spell.

obviously it has nothing to do with structs, since the spell works perfectly fine when i use CreateTimer() :/
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
>MeteoritesStructs is eventually 0, yes, after a loop at the end of the trigger.
I suppose you mean that you set it to 0 and not just destroy the struct?

I don't have any experience with structs but it isn't impossible that something like this works:

JASS:
local struct ut = unitstruct.new()
set ut.u = GetTriggerUnit()
ut.destroy()
if ut.u == GetTriggerUnit() then
   call BJDebugMsg(&quot;This might be possible&quot;)
endif

If the implementation of the structs is like this then you must set ut to 0 for the script to behave like you want, in your case that means that you have to set MeteoritesStructs to 0 yourself.

Hopefully someone that knows what he is talking about can answer this :)

Ofc the NewTimer is the cause of this, example:
JASS:
local timer t1 = NewTimer()
local timer t2
call ReleaseTimer(t1)
set t2 = NewTimer()
if t1 == t2 then
   call BJDebugMsg(&quot;This is always true&quot;)
endif

I think this is what happening with your script, only a few levels harder to catch.
 

vile

New Member
Reaction score
8
Nevermind, I found the problem
It wasnt in NewTimer()

It seems that comparing timers to timers sometimes returns the wrong timer
for example

loop
exitwhen i>x or GetExpiredTimer()==Timers
set i=i+1
endloop

This can return 0 or the wrong timer, so it seems.

When I used SetInt and SetData on the timer, it worked fine by getting the index number with GetInt.

Thanks anyhow
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top