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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top