How to stop a timer? (JASS)

staind25

TH.net Regular
Reaction score
7
I did some searching and found that you can only do this in JASS, but even the JASS code didn't seem to work. Here's what I have there:

Trigger:
  • Custom script: call DestroyTimer( udg_GYTimer[5] )


I don't know JASS, so did I enter something wrong in there? It's array #5 in the GYTimer variable. Did I correctly refer to the array, or do you type arrays differently?

(By the way, the whole goal is to stop a timer so that it doesn't continue to run, nor expire. Pausing it is not sufficient. It needs to entirely reset)

Thanks!
 

Nherwyziant

Be better than you were yesterday :D
Reaction score
96
You mean something like this?

First: So here I made a timer, and you need to create a timer window variable, then just follow. So this is how you start the timer
Trigger:
  • Actions
    • Countdown Timer - Start TimerTest as a One-shot timer that will expire in 30.00 seconds
    • Countdown Timer - Create a timer window for TimerTest with title TestTime
    • Set TimerWindow = (Last created timer window)


Second: And when you will remove it, do this
Trigger:
  • Actions
    • Countdown Timer - Start TimerTest as a One-shot timer that will expire in 30.00 seconds
    • Countdown Timer - Pause TimerTest
    • Countdown Timer - Hide TimerWindow


Third: When you need it again, do this
Trigger:
  • Actions
    • Countdown Timer - Resume TimerTest
    • Countdown Timer - Show TimerWindow
 

staind25

TH.net Regular
Reaction score
7
Heh, nope. I need to, basically, interrupt the timer.

Here's a simple example:

Team A wants to capture a base. They capture a base by starting a timer within the base. If the timer reaches zero BEFORE Team B interrupts the timer, Team A successfully captures the base. If Team B interrupts the timer, Team A does not get control of the base.

Hopefully that makes sense.

EDIT:

What I tried before the JASS was using the Destroy Timer Window action, which seems to delete the window data and make it so no one can see it, but it doesn't stop the timer. After "Team B" interrupts the timer, "Team A" still eventually gets the base, because the timer kept going even though no one could see it. I need to destroy the timer data.

I think it's mostly a question of how to write the code. I must have written the array wrong, but I don't know how to write it correctly.

Thanks for your time.
 

PrisonLove

Hard Realist
Reaction score
78
I think you're looking for [ljass]call PauseTimer(timer)[/ljass]

Edit: sorry I need to read the whole post next time. You can destroy it and then create a new timer in it's place with the time full time in it. That is, if I read the post correctly. You said you want it to reset back to the full time if one team interrupts the timer?

So:
JASS:
call DestroyTimer(yourTimer)
set yourTimer = CreateTimer()
call TimerStart(yourTimer, timeout, false, function YourFunction)  //I don't think the GUI version uses the last parameter so you'll have to look up the TimerStart BJ
 

staind25

TH.net Regular
Reaction score
7
Well, you're close, haha. I'm not sure how to put it exactly.

I need the timer to run, and then be GONE. However, I'd also like to be able to use that same timer later on (With a simple "Start Timer that'll expire in x seconds" action). As long as I can still use the same timer variable after the DestroyTimer has been called, that'll work. I just need to know how to write it in JASS.

So you say:

call DestroyTimer(your timer)

What do I write for the array? Is it like this?:

call DestroyTimer(GYTimer[5])

Or is it written differently?

(GYTimer is the name of my Timer, 5 is the array of the variable I want to use)

Thanks again. Sorry if this has been confusing.
 

8uY_YoU

New Member
Reaction score
4
Well, you're close, haha. I'm not sure how to put it exactly.

I need the timer to run, and then be GONE. However, I'd also like to be able to use that same timer later on (With a simple "Start Timer that'll expire in x seconds" action). As long as I can still use the same timer variable after the DestroyTimer has been called, that'll work. I just need to know how to write it in JASS.

So you say:

call DestroyTimer(your timer)

What do I write for the array? Is it like this?:

call DestroyTimer(GYTimer[5])

Or is it written differently?

(GYTimer is the name of my Timer, 5 is the array of the variable I want to use)

Thanks again. Sorry if this has been confusing.

Put udg_ before your variable
EX : udg_GYTimer[5]
 

staind25

TH.net Regular
Reaction score
7
Hmm, that's what I thought...that's how I had it written...but for some reason it didn't destroy the timer =\
 

staind25

TH.net Regular
Reaction score
7
Because destroying the timer window doesn't stop the timer. All it does is makes it so that no one can see it. The timer continues to run, and eventually expires when it shouldn't.
 

Tyman2007

Ya Rly >.
Reaction score
74
When a timer is destroyed another can take its place using the same variable.

I suggest using a timer system such as TimerUtils as their methods of creating/destroying timers are much better, provided you're one who will get into structs :p
 

staind25

TH.net Regular
Reaction score
7
Yeah I JUST ran into this problem, haha. Finally got the code to work (I took a break...just now started again), but then found out that the data was unusable after it was destroyed (Which I was afraid of).

So since you say it can be replaced by another variable...what action do I use to recreate the variable mid-game like that?

If I can't do it fairly easily in GUI I'll look for that system :) Thanks much.
 

Tyman2007

Ya Rly >.
Reaction score
74
[ljass]call CreateTimer()[/ljass] will create the timer without starting it allowing it to be used once again after destroying it.
 

Jedi

New Member
Reaction score
63
I still don't get what are you talking about?Just pause and start the same timer again?Do that 100000 times?What is the problem?
 

Tyman2007

Ya Rly >.
Reaction score
74
Overwriting variables can cause leaks. That's why he doesn't want to probably :p I believe starting a timer constantly can cause issues if not properly recycled.
 

staind25

TH.net Regular
Reaction score
7
If I pause the timer, doesn't it freeze it at that specific time? Say I have a timer set to 15 seconds, then it runs for 5 seconds, and I pause it. Doesn't it pause at 10 seconds? I can't have that. I'd need it to go back to 15.

I'm having issues with call CreateTimer()

I don't know hardly anything about JASS, so I need a little help on how to use it. I put my variable in the parentheses and got an error, so I figured that's not how to use it...here's what that part of the trigger looks like at the moment:

Trigger:
  • Then - Actions
    • Custom script: call DestroyTimer(udg_GYTimer[5])
    • Custom script: call CreateTimer()
    • Countdown Timer - Destroy GYTimerWindow[5]


When I tried this, the timer never destroyed. I'm guessing the CreateTimer() somehow prevented that. Do I need to put the CreateTimer() in a different spot or something?

Thanks again :)


EDIT:

On second thought, I suppose pausing the timer, then creating the timer over the paused timer would work...no idea why I didn't think of that, haha. My bad. Didn't make that connection. But if it does leak, then I prefer another way...this is a large-scale map and I need to make it as leakless as possible.

EDIT2:

Bahaha. The reason I was having issues with the CreateTimer was because the trigger was disabled! I forgot that when it detects JASS errors, it disables the trigger...wow.

It looks like I got it to work :) It'll take a lot of testing and I'm sure I'll have more questions for you guys, but for now, thank you all very much!
 

staind25

TH.net Regular
Reaction score
7
(Posted a new post because the last was getting rather long)

I am so confused. I just came back from a 2-3 hour break, and now it doesn't work. I didn't change anything to my knowledge, but now the CreateTimer() part doesn't work. When I try to reuse the timer, I just get a timer window with no time in it.

Looking at my last post, is there anything in the JASS that I'm using wrong? Is it possible to specify which variable I want to "CreateTimer" for? Whenever I put my variable in there, it results in an error.

Thanks.
 

Jedi

New Member
Reaction score
63
Overwriting variables can cause leaks.

There is no such a thing like that, and we are not overwriting variable, we are just starting the timer again.

Anyway, you are creating a timer but don't use it.

Trigger:
  • Custom script: set udg_GYTimer[5] = CreateTimer()


Edit:It is better to destroy timer window first, at least I got some errors when didn't do that.
 

staind25

TH.net Regular
Reaction score
7
Ahh, thanks. I'll give that a shot. I tried using TimerUtils but it's all way over my head due to my lack of JASS knowledge...hopefully what I was doing before will work.

---------------------------------------------------------------------

Edit:

New problem. The timer interrupts just fine, but consider this scenario:

Timer starts -> Timer is interrupted -> Timer starts again -> Timer expires successfully

In this situation, the "Timer Expires" trigger doesn't run. This only doesn't work when the timer was interrupted before. The JASS must be changing the variable somehow.

Here are the relevant parts of the triggers:


Trigger 1 - Starts timer

Trigger:
  • Actions
    • Countdown Timer - Create a timer window for GYTimer[5] with title Stonehearth GY
    • Set GYTimerWindow[5] = (Last created timer window)
    • Countdown Timer - Start GYTimer[5] as a One-shot timer that will expire in 15.00 seconds


Trigger 2 - Interrupts timer

Trigger:
  • Actions
    • Custom script: call DestroyTimer(udg_GYTimer[5])
    • Countdown Timer - Destroy GYTimerWindow[5]
    • Custom script: set udg_GYTimer[5] = CreateTimer()
    • Custom script: call CreateTimer()


Trigger 3 - Timer expires without interruption

Trigger:
  • Events
    • Time - GYTimer[5] expires



For some reason, the event in trigger 3 isn't happening. The variable data must have been altered somehow in trigger 2, but I'm not sure how to correct for that. Any ideas?

Thanks.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • 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!
  • 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

      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