1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Using globals instead of locals for instant actions

Discussion in 'World Editor Help Zone' started by ToldYouSo, Sep 23, 2019.

  1. ToldYouSo

    ToldYouSo

    Joined:
    May 24, 2016
    Messages:
    124
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Code (Text):

    globals
    timer T
    integer ID
    endglobals

    function Rain_Loop takes nothing returns nothing
    set T = GetExpiredTimer()
    set ID = GetHandleId(T)
    ... actions
    call FlushChildHashtable(Hash,ID)
    call PauseTimer(T)
    call DestroyTimer(T)
    endfunction
    Sorry, didnt find some sort of my question. As you can see, for "instant actions" function I prefer to use global variables, coz it saves of a lot of time. So I wonder is it completely valid?
     
  2. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    3,030
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Yes this is totally fine.
     
  3. Ceday

    Ceday

    Joined:
    Feb 22, 2010
    Messages:
    1,077
    Resources:
    0
    Resources:
    0
    If you use same global variable across multiple places, and "... actions" in your example causes another trigger to run which use same global variable you will encounter problems.
     
  4. ToldYouSo

    ToldYouSo

    Joined:
    May 24, 2016
    Messages:
    124
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Explain what do you mean by that? Running a trigger exactly at the same time?
     
  5. Ceday

    Ceday

    Joined:
    Feb 22, 2010
    Messages:
    1,077
    Resources:
    0
    Resources:
    0
    Lets say you have two triggers like this (I just made it up, so scenario may not make sense but problem is real):
    • Trigger1
      • Events
        • Unit - Enters region MIDDLE
      • Conditions
      • Actions
        • Set GlobalUnit = (Triggering Unit)
        • Unit - Cause GlobalUnit to damage MAP_BOSS
        • Unit - Pause GlobalUnit



    • Trigger2
      • Events
        • Unit - Take damage event
      • Conditions
      • Actions
        • ------- Create blood effect when a unit takes damage -------
        • Set GlobalUnit = (Damaged Unit)
        • Special Effect - create blood effect on GlobalUnit
        • Special Effect - (Destroy last created special effect)


    In this example 2nd action of the Trigger1 causes Trigger2 to run, which overrides GlobalUnit variable. After Trigger2 is finished, execution is switched back to Trigger1 3rd action but GlobalUnit is a different unit now.


    I will let IcemanBo explain better:
    Strange location issues
    [GUI] - [How-to] Loop In GUI!
     
  6. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,166
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Locals should be used over globals. It's safer and easier to debug.
     
  7. Wrda

    Wrda

    Joined:
    Nov 18, 2012
    Messages:
    1,128
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    A better question is: Why would you use variables in those triggers? @Ceday
    It's completely unnecessary.
     
  8. JsonDalao

    JsonDalao

    Joined:
    Aug 6, 2019
    Messages:
    66
    Resources:
    0
    Resources:
    0
    Using Lua does not have this problem
     
  9. Ceday

    Ceday

    Joined:
    Feb 22, 2010
    Messages:
    1,077
    Resources:
    0
    Resources:
    0
    At the start of the post, I literally wrote I made up that scenario and it may not make sense. Something more realistic would be a GUI user who cleans all locations with same variable or someone who uses a global unit group for all temp stuff.