Loop Question

San-D

New Member
Reaction score
15
I heard somewhere that u shouldnt use wait actions in a loop. I have a trigger that whirpool spin that "gravitates" a target to the caster the trigger is the following:
VARS: Caster-Unit
Target-Unit
Distance-Real
Angle-Real

Code:
Whirpool
    Events
        Unit - A unit Begins casting an ability
    Conditions
        (Ability being cast) Equal to Whirpool 
    Actions
        Set Caster = (Casting unit)
        Set Target = (Target unit of ability being cast)
        Set Angle = (Angle from (Position of Caster) to (Position of Target))
        Set Distance = (Distance between (Position of Caster) and (Position of Target))
        Unit - Pause Caster
        Unit - Pause Target
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                Distance Greater than or equal to 100.00
            Then - Actions
                For each (Integer A) from 100 to (Integer(Distance)), do (Actions)
                    Loop - Actions
                        Wait 0.01 seconds
                        Unit - Move Target instantly to ((Position of Caster) offset by Distance towards Angle degrees)
                        Unit - Create 1 Dummy for Player 1 (Red) at (Position of Target) facing Default building facing degrees
                        Unit - Add a 0.01 second Generic expiration timer to (Last created unit)
                        Set Angle = (Angle + 1.00)
                        Set Distance = (Distance - 1.00)
            Else - Actions
                Unit - Make Target Vulnerable
                Do nothing
        Unit - Unpause Target
        Unit - Unpause Caster


The problem: Everything is just perfect, ONLY it doesnt unpause the uniits!
(Also when i loop the motion its much slower when I doo a seperate trigger (E: Every 0.01 sec; A: move unit...)

REP TO THE ONE WHO SOLVES IT!!!!!
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> Also when i loop the motion its much slower when I doo a seperate trigger

That's normal. And the reason why periodic stuff should run on periodic triggers or timers.

This mess you posted is also unreadable.
Use "copy as text"...

What happens if the distance is greater than 100?
 

San-D

New Member
Reaction score
15
I think that 100 is a good distance to stop the motion. If it was 0, then the Target would try to merge with the Caster, and crazy stuff would happen. 100 means that I want the Target to stop at 100 of the Caster

- I would like to point out, that I tied to use a separate trigger using

Code:
Untitled Trigger 002
    Events
        Unit - A unit Begins casting an ability
    Conditions
        (Ability being cast) Equal to Spin (Neutral Hostile)
    Actions
        Set Caster = (Casting unit)
        Set Target = (Target unit of ability being cast)
        Set Angle = (Angle from (Position of Caster) to (Position of Target))
        Set Distance = (Distance between (Position of Caster) and (Position of Target))
        Set Sine = 90.00
        Set SpinTrue_False = True
        Unit - Pause Caster
        Unit - Pause Target
        Trigger - Turn on Spin <gen>
        Wait ((Distance between (Position of Caster) and (Position of Target)) / 100.00) game-time seconds
        Unit - Unpause Caster
        Unit - Unpause Target
        Trigger - Turn off Spin <gen>
        Set SpinTrue_False = False

AND
Code:
Spin
    Events
        Time - Every 0.01 seconds of game time
    Conditions
    Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (SpinTrue_False Equal to True) and (Distance Greater than or equal to 100.00)
            Then - Actions
                Unit - Move Target instantly to ((Position of Caster) offset by Distance towards Angle degrees)
                Unit - Create 1 Dummy for Player 1 (Red) at (Position of Target) facing Default building facing degrees
                Unit - Add a 0.01 second Generic expiration timer to (Last created unit)
                Set Angle = (Angle + 1.00)
                Set Distance = (Distance - 1.00)
                Set Timer = (Timer + 1.00)
            Else - Actions
                Unit - Unpause Caster
                Unit - Unpause Target
                Set SpinTrue_False = False
                Trigger - Turn off (This trigger)

where SpinTrue_False is a boolean var, to control when it stops, but it doesnt, once it reaces the 100 ofset, they stay paused and it continues spawning Dummies non-stop!
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Much more readable now :p

Tried with "starts the effect of" as event yet?
Also, there is only one single unit on the map that could cast this spell?
 

San-D

New Member
Reaction score
15
Sorry about that, but I dont know how to make multi-instance spell or whatever, maybe a array will help, but YES, only 1 unit can! As for the Starts the effect thing That wont help, the problem is the units stay paused AND it continues spawning Dummis, as if its trying to move closer to the caster!
 

San-D

New Member
Reaction score
15
:p:p:p:p:banghead: Stupid me! The chnge to Starts the effect of an ability realy DID the trick- Here is the final version!
Code:
Whirpool
    Events
        Unit - A unit Starts the effect of an ability
    Conditions
        (Ability being cast) Equal to Whirpool 
    Actions
        Set Caster = (Casting unit)
        Set Target = (Target unit of ability being cast)
        Set Angle = (Angle from (Position of Caster) to (Position of Target))
        Set Distance = (Distance between (Position of Caster) and (Position of Target))
        Unit - Pause Caster
        Unit - Pause Target
        Trigger - Turn on Whirpool Spin <gen>
        Wait until (Distance Less than or equal to 100.00), checking every 0.10 seconds
        Trigger - Turn off Whirpool Spin <gen>
        Unit - Unpause Target
        Unit - Unpause Caster

+

Code:
Whirpool Spin
    Events
        Time - Every 0.01 seconds of game time
    Conditions
    Actions
        Unit - Move Target instantly to ((Position of Caster) offset by Distance towards Angle degrees)
        Unit - Create 1 Dummy for Player 1 (Red) at (Position of Target) facing Default building facing degrees
        Unit - Add a 0.01 second Generic expiration timer to (Last created unit)
        Set Angle = (Angle + 1.00)
        Set Distance = (Distance - 1.00)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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