HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

MUI timer Problem, please help.

12-21-2009, 03:45 PM#1
SmileyJeff
Hi all i was playing around with timers and wanted to do a MUI version of it but i got some problem. Why is my below code not MUI for timers? The 2nd time of casting thunderclap won't will stop the timer and won't show the time left anymore.

I've also attach the map below so you guys can test it.

Trigger:
Melee Initialization
Collapse Events
Map initialization
Conditions
Collapse Actions
Visibility - Disable fog of war
Visibility - Disable black mask
Hero - Learn skill for Mountain King 0000 <gen>: Thunder Clap
Unit - Set level of Thunder Clap for Mountain King 0000 <gen> to 3
-------- hashtable --------
Hashtable - Create a hashtable
Set timetable = (Last created hashtable)

Trigger:
cast
Collapse Events
Unit - A unit Starts the effect of an ability
Collapse Conditions
(Ability being cast) Equal to Thunder Clap
Collapse Actions
Countdown Timer - Start timer as a One-shot timer that will expire in 10.00 seconds
Set tempPos = (Position of Spell Breaker 0002 <gen>)
Unit - Create 1 Footman for Player 1 (Red) at tempPos facing Default building facing degrees
Unit Group - Add (Last created unit) to dummygroup
Hashtable - Save Handle Oftimer as (Key time) of (Key (Last created unit)) in timetable
Trigger - Turn on time <gen>
Game - Display to (All players) the text: |cff00FF00START!|r
Custom script: call RemoveLocation(udg_tempPos)

Trigger:
time
Collapse Events
Time - Every 0.10 seconds of game time
Conditions
Collapse Actions
Collapse Unit Group - Pick every unit in dummygroup and do (Actions)
Collapse Loop - Actions
Collapse For each (Integer A) from 0 to 10, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Elapsed time for (Load (Key time) of (Key (Picked unit)) in timetable)) Equal to (Real((Integer A)))
Collapse Then - Actions
Game - Display to (All players) the text: (Time Left: |cffffcc00 + ((String((10 - (Integer A)))) + |r))
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(10 - (Integer A)) Equal to 0
Collapse Then - Actions
Game - Display to (All players) the text: |cffFF0000END!|r
Unit Group - Remove (Picked unit) from dummygroup
Unit - Kill (Picked unit)
Hashtable - Clear all child hashtables of child (Key (Picked unit)) in timetable
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Number of units in dummygroup) Equal to 0
Collapse Then - Actions
Trigger - Turn off (This trigger)
Else - Actions
Else - Actions
Else - Actions

Is there a way to reset the timer whenever it is called?
If any of you know the problem please let me know. Thanks in advance!
Attached Files
File type: w3xtimertestmap2.w3x (18.1 KB)
12-21-2009, 10:50 PM#2
Themerion
Quote:
Why is my below code not MUI for timers?

Because you use only 1 timer. You need JASS in order to create multiple timers.Here's what you can do:

The script below will cause <timer_variable> to point at a new timer, which you can start separately from other timers (using start timer). ( Replace <timer_variable> with whatever your variable is called: )
Trigger:
Custom Script: set udg_<timer_variable> = CreateTimer()
Countdown Timer - Start udg_<timer_variable> as a One-shot timer expiring in 10 seconds

When you are done with your timer, you should destroy it. Just be careful, because after you've destroyed it, <timer_variable> will point at a destroyed timer ( = null). You can't use StartTimer on <timer_variable> again, unless you first create another timer for it (using CreateTimer).

Trigger:
Custom Script: call DestroyTimer( udg_<timer_variable> )

This is sort of a workaround and hax for your implementation. In JASS, you can make timers call functions when they expire, thus eliminating the need for the extra trigger running every ~0.10 seconds... (hint: triggers are inconvenient, JASS is not :)
12-22-2009, 01:05 AM#3
SmileyJeff
That works nicely [: Thanks alot!

After trying for the 1st time it work flawlessly. But now, my text ain't displaying, sometimes it does, sometimes it doesnt. It will only display when elapsed time is 0. Although it is working fine.

Here is my code. Is there anything i did wrong this time? I can't destroy the timer because i have to keep using it.

Trigger:
cast
Collapse Events
Unit - A unit Starts the effect of an ability
Collapse Conditions
(Ability being cast) Equal to Thunder Clap
Collapse Actions
Custom script: set udg_timer = CreateTimer()
Countdown Timer - Start timer as a One-shot timer that will expire in 10.00 seconds
Set tempPos = (Position of Spell Breaker 0002 <gen>)
Unit - Create 1 Footman for Player 1 (Red) at tempPos facing Default building facing degrees
Unit Group - Add (Last created unit) to dummygroup
Hashtable - Save Handle Oftimer as (Key time) of (Key (Last created unit)) in timetable
Trigger - Turn on time <gen>
Game - Display to (All players) the text: |cff00FF00START!|r
Custom script: call RemoveLocation(udg_tempPos)

Trigger:
time
Collapse Events
Time - Every 0.10 seconds of game time
Conditions
Collapse Actions
Collapse Unit Group - Pick every unit in dummygroup and do (Actions)
Collapse Loop - Actions
Set timer = (Load (Key time) of (Key (Picked unit)) in timetable)
Collapse For each (Integer A) from 0 to 10, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Elapsed time for timer) Equal to (Real((Integer A)))
Collapse Then - Actions
-------- Not Displaying --------
Game - Display to (All players) the text: (Time Left: |cffffcc00 + ((String((10 - (Integer A)))) + |r))
-------- ----------------------- --------
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(10 - (Integer A)) Equal to 0
Collapse Then - Actions
Game - Display to (All players) the text: |cffFF0000END!|r
Unit Group - Remove (Picked unit) from dummygroup
Unit - Kill (Picked unit)
Hashtable - Clear all child hashtables of child (Key (Picked unit)) in timetable
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Number of units in dummygroup) Equal to 0
Collapse Then - Actions
Trigger - Turn off (This trigger)
Else - Actions
Else - Actions
Else - Actions
12-22-2009, 09:51 AM#4
Anitarf
Quote:
Originally Posted by Themerion
Trigger:
Custom Script: call DestroyTimer( udg_<timer_variable> )

This is sort of a workaround and hax for your implementation.
It is also wrong, since if he creates multiple timers this line will destroy the latest timer. There is simply no good way to use timers in GUI.

If you could describe what you want your spell to do, perhaps we can work something out.
12-22-2009, 01:40 PM#5
SmileyJeff
I've solve my problem, although inefficient compared to timers. Its the only way i can do it in GUI for MUI.

I tried to create a spell, which has a channel time, the longer it channels, when release, it will do more damage. I used periodic timer every 0.10seconds, and then add my duration += 0.10seconds. when it hits 1, i will know it is 1 second and so on..

Thanks for the help and clarification [:
I will try to look into JASS more.
12-22-2009, 07:36 PM#6
Themerion
Quote:
Originally Posted by Anitarf
[using DestroyTimer] is also wrong, since if he creates multiple timers this line will destroy the latest timer. There is simply no good way to use timers in GUI.

Trigger:
Set timer = (Load (Key time) of (Key (Picked unit)) in timetable)
Custom Script: call DestroyTimer(udg_timer)

I agree that there's no good way, but look at his code. He's loading the timer from a hash-table every time, so it should be safe to destroy the timer in this case (unless the trigger casts the same spell :P ).