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.

      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