Values not being saved

Discussion in 'World Editor Help' started by Klein~, Aug 25, 2017.

  1. Klein~

    Klein~ Active Member

    Ratings:
    +0 / 0 / -0
    Hello

    I am working in the following trigger and I am having one problem when I assign values to indexed variables using "For each".

    Trigger:
    • Events
      • Unit - A unit Starts the effect of an ability
      • Conditions
        • (Ability being cast) Equal to Resistance Crusher
      • Actions
        • -------- Spells --------
        • Set ImunitySpells[1] = Spell Immunity
        • Set ImunitySpells[2] = Spell Immunity (Archimonde)
        • Set ImunitySpells[3] = Spell Immunity (Dragon)
        • Set ImunitySpells[4] = Spell Immunity (Neutral Hostile)
        • Set ImunitySpells[5] = Resistant Skin
        • Set ImunitySpells[6] = Resistant Skin (Neutral Hostile 1)
        • Set ImunitySpells[7] = Resistant Skin (Neutral Hostile 2)
        • -------- Buffs --------
        • Unit - Remove Divine Shield buff from (Target unit of ability being cast)
        • Unit - Remove Anti-magic Shell buff from (Target unit of ability being cast)
        • Unit - Remove Anti-magic Shell (Extra) buff from (Target unit of ability being cast)
        • Unit - Remove Avatar buff from (Target unit of ability being cast)
        • -------- Triggers --------
        • For each (Integer Counter) from 1 to 7, do (Actions)
          • Loop - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Level of ImunitySpells[Counter] for (Target unit of ability being cast)) Equal to 1
              • Then - Actions
                • Hashtable - Save 1 as ISpellCounter[Counter] of (Key (Target unit of ability being cast)) in GlobalHashtable
                • Unit - Remove ImunitySpells[Counter] from (Target unit of ability being cast)
              • Else - Actions
                • Hashtable - Save 0 as ISpellCounter[Counter] of (Key (Target unit of ability being cast)) in GlobalHashtable
            • Game - Display to (All players) for 20.00 seconds the text: (String((Load ISpellCounter[Counter] of (Key (Target unit of ability being cast)) from GlobalHashtable)))
        • Hashtable - Save 0.00 as (Key mctime) of (Key (Target unit of ability being cast)) in GlobalHashtable
        • Game - Display to (All players) for 20.00 seconds the text: (String((Load ISpellCounter[1] of (Key (Target unit of ability being cast)) from GlobalHashtable)))
        • Unit Group - Add (Target unit of ability being cast) to MagicCurseGroup



    The goal of this was to identify what skills the unit has and store values to save them. Exemple:

    If the skill is used on Dryad unit (Night Elf) which has Spell Immunity skill, the "For each" part should store:

    ISpellsCounter[1] from Dryad = 1
    ISpellsCounter[2] from Dryad = 0
    ISpellsCounter[3] from Dryad = 0
    ISpellsCounter[4] from Dryad = 0
    ISpellsCounter[5] from Dryad = 0
    ISpellsCounter[6] from Dryad = 0
    ISpellsCounter[7] from Dryad = 0

    But it is actually just storing zeros.
    I made some tests and the first "game chat" command displays the right values (1, 0, 0, 0, 0, 0, 0), but the second "game chat" command displays 0 instead of 1 in the first slot.

    If someone could help me identify this error, I would be grateful.
     
  2. vypur85

    vypur85 Hibernate

    Ratings:
    +797 / 0 / -0
    > For each (Integer Counter) from 1 to 7, do (Actions)

    Perhaps because you're using the wrong counter?

    In the actions, you used "Counter" instead of "Integer Counter".
     
  3. Klein~

    Klein~ Active Member

    Ratings:
    +0 / 0 / -0
    The counter itself is an integer, like A or B counters.
     
  4. vypur85

    vypur85 Hibernate

    Ratings:
    +797 / 0 / -0
    I see... I kinda forgot the word "Integer" is there by default.

    Anyways,

    > ISpellCounter[Counter]
    Did you define this value? If the value is zero for all the array, then this value will return zero for every Counter array.
    Meaning to say that your hashtable will always load ZERO + Key of (Target unit of ability being cast).

    This is the most likely cause of your value being overwritten by the 2 to 7 iteration of the loop. To proof this, just change "For each (Integer Counter) from 1 to 7, do (Actions)" to "For each (Integer Counter) from 1 to 1, do (Actions)". I believe it will display 1 and 1 correctly.
     

Share This Page