1. Find your way through the deepest dungeon in the 18th Mini Mapping Contest Poll.
    Dismiss Notice
  2. A brave new world lies beyond the seven seas. Join the 34th Modeling Contest today!
    Dismiss Notice
  3. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
Hive 3 Remoosed BETA - NOW LIVE. Go check it out at BETA Hive Workshop! Post your feedback in this new forum BETA Feedback.
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Trigger] Local variable for loop

Discussion in 'Triggers & Scripts' started by Triax, Feb 11, 2009.

  1. Triax

    Triax

    Joined:
    Feb 5, 2008
    Messages:
    106
    Resources:
    0
    Resources:
    0
    Hi! =)

    I just made an ability which creates some dust around the caster and spawns a wurm after that.

    It's somehow not working because I use a local variable for the loop (at least I guess that's why), but I have to do so, otherwise other triggers will surely stop this one from working correctly.
    I also read somewhere that you can declare just one local variable in GUI. Is that true?

    Ah, and please tell me if I got any memory leaks in this.

    • Dune Worm
      • Events
        • Unit - A unit starts the effect of an ability
      • Conditions
        • (Ability being cast) Gleich Dune Worm
      • Actions
        • Custom script: local location udg_Point
        • Custom script: local integer udg_Integer
        • Animation - Play (Triggering unit)'s spell animation
        • Set Point = (Position of (Triggering unit))
        • For each (Integer Integer) from 1 to 20, do (Actions)
          • Loop - Actions
            • Set Point_2 = (Point offset by 256.00 towards ((Real(Integer)) x 18.00) degrees)
            • Special Effect - Create a special effect at Point_2 using Objects\Spawnmodels\Undead\ImpaleTargetDust\ImpaleTargetDust.mdl
            • Special Effect - Destroy (Last created special effect)
            • Set Integer_2 = Integer
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • Integer_2 Gleich 20
                • (Terrain pathing at Point_2 of type Begehbarkeit is off) Gleich False
                • (Point_2 is blighted) Gleich False
              • Then - Actions
                • Unit - Create 1 Dune Worm for (Owner of (Triggering unit)) at Point_2 facing Preset for buildings degrees
              • Else - Actions
            • Point - Remove Point_2
            • Wait 0.01 seconds
        • Point - Remove Point


    Thank you for help. =)
    Triax
     
    Last edited: Feb 11, 2009
  2. Vegavak

    Vegavak

    Joined:
    Mar 16, 2006
    Messages:
    1,010
    Resources:
    0
    Resources:
    0
    Why are you using locals?
     
  3. neavea

    neavea

    Joined:
    Oct 17, 2006
    Messages:
    151
    Resources:
    0
    Resources:
    0
    instead of "Einheit - A unit starts the effect of an ability" you should use "unit casts an ability"

    also same question as vegavak...
     
  4. Triax

    Triax

    Joined:
    Feb 5, 2008
    Messages:
    106
    Resources:
    0
    Resources:
    0
    Uh, you're kidding, aren't you?

    First of all, if I use "casts an ability", the effect will start even if the spell gets interrupted.

    And I need a local point to store the position where the caster stood when the effect starts and a local integer for the loop so it can't be manipulated by other triggers.
     
  5. Eleandor

    Eleandor

    Joined:
    Aug 21, 2005
    Messages:
    3,681
    Resources:
    2
    Models:
    1
    Tutorials:
    1
    Resources:
    2
    You also can't use more than 1 local "global" variable, i.e. udg_Integer won't work as you've already used udg_Point.

    If you would remove the "udg_", it should work. But in that case, you can only use the local variable in pure jass, not gui.
     
  6. neavea

    neavea

    Joined:
    Oct 17, 2006
    Messages:
    151
    Resources:
    0
    Resources:
    0
    My mistake... :zip:

    was reading it with remote access... :grin::thumbs_up:
     
  7. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,952
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    You do notice that by adding a wait, the loop will take around 5.4 seconds, yea?

    If you really have to use locals, just use Jass.

    Code (vJASS):

    local integer iterator = 0

    // actions

    loop
    exitwhen iterator == 20

    // actions

    iterator = iterator + 1
    endloop
     
     
  8. ZiggyMcjoney

    ZiggyMcjoney

    Joined:
    May 4, 2008
    Messages:
    109
    Resources:
    1
    Maps:
    1
    Resources:
    1
    You could simply convert it to JASS, and just change any of your 'udg_Point's and any other local globals to REAL locals.

    Providing you can understand at least a TINY bit of JASS.
     
  9. Triax

    Triax

    Joined:
    Feb 5, 2008
    Messages:
    106
    Resources:
    0
    Resources:
    0
    I think it's not that hard for me to learn JASS, but I don't like to. <.<
    But I should be able to do the variable thing. ;D
    The basic thing was that I didn't want to use any JASS in my triggers, but this should be the easiest way.

    Thanks for your effort. =)

    Btw, why can only one global variable be 'local'?
     
  10. Triax

    Triax

    Joined:
    Feb 5, 2008
    Messages:
    106
    Resources:
    0
    Resources:
    0
    I tried to convert it to JASS, and it went well until I tried to integrate the if into the main function.

    Looks like this now:
    Code (vJASS):
    function Trig_Dune_Worm_JASS_Conditions takes nothing returns boolean
        if ( not ( GetSpellAbilityId() == 'A02B' ) ) then
            return false
        endif
        return true
    endfunction

    function Trig_Dune_Worm_JASS_Actions takes nothing returns nothing
        local location udg_Point
        local integer Integer
        call SetUnitAnimation( GetTriggerUnit(), "spell" )
        set udg_Point = GetUnitLoc(GetTriggerUnit())
        set udg_Integer_2 = GetRandomInt(0, 20)
        set Integer = udg_Integer_2
        loop
            exitwhen Integer > ( udg_Integer_2 + 20 )
            set udg_Point_2 = PolarProjectionBJ(udg_Point, 256, ( I2R(Integer) * 18.00 ))
            call AddSpecialEffectLocBJ( udg_Point_2, "Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl" )
            call DestroyEffectBJ( GetLastCreatedEffectBJ() )
            if  ( Integer == ( udg_Integer_2 + 20 ) ) and
                ( IsTerrainPathableBJ(udg_Point_2, PATHING_TYPE_WALKABILITY) == false ) and
                ( IsPointBlightedBJ(udg_Point_2) == false )
            then
               call CreateNUnitsAtLoc( 1, 'o001', GetOwningPlayer(GetTriggerUnit()), udg_Point_2, bj_UNIT_FACING )
            endif
            call RemoveLocation( udg_Point_2 )
            call TriggerSleepAction( 0.01 )
            set Integer = Integer + 1
        endloop
        call RemoveLocation( udg_Point )
    endfunction

    //===========================================================================
    function InitTrig_Dune_Worm_JASS takes nothing returns nothing
        set gg_trg_Dune_Worm_JASS = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( gg_trg_Dune_Worm_JASS, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( gg_trg_Dune_Worm_JASS, Condition( function Trig_Dune_Worm_JASS_Conditions ) )
        call TriggerAddAction( gg_trg_Dune_Worm_JASS, function Trig_Dune_Worm_JASS_Actions )
    endfunction

    I had a look on a tutorial for if-then-else in JASS, and I think that the syntax is correct. So what's wrong with this?
     
  11. Eleandor

    Eleandor

    Joined:
    Aug 21, 2005
    Messages:
    3,681
    Resources:
    2
    Models:
    1
    Tutorials:
    1
    Resources:
    2
    I don't think you can use linebreaks in boolean expressions. Try putting the whole condition on one line (and don't use BJ's)
     
  12. Triax

    Triax

    Joined:
    Feb 5, 2008
    Messages:
    106
    Resources:
    0
    Resources:
    0
    Makes no difference. :S
    (What you mean with BJ?)

    (JASSHelper says I got a syntax error in the if-line. I put in a break there so the line just contained "if", but I still got the error. Same with "if (" (... ")").)
     
  13. Element of Water

    Element of Water

    Joined:
    Aug 3, 2008
    Messages:
    2,298
    Resources:
    5
    Spells:
    3
    Tutorials:
    1
    JASS:
    1
    Resources:
    5
    Put the whole "if" on the same line, up to "then". It seems you may be used to coding c++ or some other language where you can put random linebreaks in statements. And btw you don't need any of those parentheses apart from around function calls. The if line should be like this:
    Code (vJASS):
    if Integer == udg_Integer_2 + 20 and IsTerrainPathableBJ(udg_Point_2, PATHING_TYPE_WALKABILITY) == false and IsPointBlightedBJ(udg_Point_2) == false then

    Since you don't know Jass very well I wouldn't bother with changing the BJs. It only makes the code run a few milliseconds faster.
     
  14. Triax

    Triax

    Joined:
    Feb 5, 2008
    Messages:
    106
    Resources:
    0
    Resources:
    0
    Yay, it works! My first trigger in JASS. =D

    I'll add some more things, let's see whether I get any more problems. But thanks so far. =)