• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Global variables in Jass

Status
Not open for further replies.
Level 2
Joined
Jul 21, 2020
Messages
14
I have the Spell from Carnerox and want to add global variables, but I don't have that much experience with Jass. I want to write the healed value in global variables but I have no idea how. Can anyone help me?
It is about the following variables:

set udg_MB_Healed[0] = ( udg_MB_Healed[0] + d );
set udg_MB_HealedTotal[0] = ( udg_MB_HealedTotal[0] + d );
set udg_MB_Healed[GetConvertedPlayerId(GetOwningPlayer(u))] = ( udg_MB_Healed[GetConvertedPlayerId(GetOwningPlayer(u))] + d );
set udg_MB_HealedTotal[GetConvertedPlayerId(GetOwningPlayer(u))] = ( udg_MB_HealedTotal[GetConvertedPlayerId(GetOwningPlayer(u))] + d );

The way I have tried it does not work.

JASS:
//! zinc
library HealingWave requires ChainSys{

    function onCondition()->boolean{
        return GetSpellAbilityId()=='A0DG';
    }
   
    function onHeal()->boolean{
        unit u=udg_HeroShadowhunter;
        real d=Chain_LastDamage;
        set udg_MB_Healed[0] = ( udg_MB_Healed[0] + d );
        set udg_MB_HealedTotal[0] = ( udg_MB_HealedTotal[0] + d );
        set udg_MB_Healed[GetConvertedPlayerId(GetOwningPlayer(u))] = ( udg_MB_Healed[GetConvertedPlayerId(GetOwningPlayer(u))] + d );
        set udg_MB_HealedTotal[GetConvertedPlayerId(GetOwningPlayer(u))] = ( udg_MB_HealedTotal[GetConvertedPlayerId(GetOwningPlayer(u))] + d );
        //BJDebugMsg(GetUnitName(u)+" was healed for "+R2S(d)+"!");
        return false;
    }

    function onFilter()->boolean{
        return !IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE);
    }



    function onAction(){
        unit u = GetTriggerUnit(),
        t = GetSpellTargetUnit();
        integer l=GetUnitAbilityLevel(u,'A0DG');

        real F = udg_SpHealingWaveFlatt;
        real FF = udg_SpHealingWaveFlattF;
        real P = udg_SpHealingWavePercent;
        real PF = udg_SpHealingWavePercentF;
        real S = I2R(GetHeroStatBJ(bj_HEROSTAT_INT, u, true));
        real a = ( ( ( F * l ) + FF ) + ( S * ( ( l * P ) + PF ) ) );
       
        boolexpr b=Filter(function onFilter);
        Chain_HealingWave(u,  //Caster
        t,               //Target
        a,                  //Heal
        ((1.0*l)-10.0)*0.01,  //Heal Reduction
        500.0,                //Radius
        (1*l)+2,              //Max Bounces
        0.33,                 //Bounce Intervals
        false,                //Doesn't Hit Caster
        b,                    //Target Filter
        function onHeal);     //Triggered Impact
        ClearTextMessages();

    }

    function onInit(){
        trigger t=CreateTrigger();
            TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT);
            TriggerAddCondition(t,Condition(function onCondition));
            TriggerAddAction(t,function onAction);
        t=null;
    }       
}
//! endzinc
 
Last edited:
Level 2
Joined
Jul 21, 2020
Messages
14
without my global variables the commented out one (//BJDebugMsg(GetUnitName(u)+" was healed for "+R2S(d)+"!")) had worked, "d" has a value. If I use the global variables in the GUI it also works, here is an example where I have already used them.

  • Holy Light P
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to SpHolyLightP
    • Actions
      • -------- Set General Variables --------
      • Set VariableSet Spell = SpHolyLightP
      • Set VariableSet DamageFlatt = SpHolyLightPFlatt
      • Set VariableSet DamageFlattF = SpHolyLightPFlattF
      • Set VariableSet DamagePercent = SpHolyLightPPercent
      • Set VariableSet DamagePercentF = SpHolyLightPPercentF
      • Set VariableSet DamageUnitTrigger = HeroPaladin
      • Set VariableSet DamageAbilityLevel = (Real((Level of Spell for DamageUnitTrigger)))
      • Set VariableSet DamageStats = (Real((Strength of DamageUnitTrigger (Include bonuses))))
      • -------- Calculate Damage --------
      • Set VariableSet SpHolyLightPDamage = (((DamageFlatt x DamageAbilityLevel) + DamageFlattF) + (DamageStats x ((DamageAbilityLevel x DamagePercent) + DamagePercentF)))
      • Set VariableSet SpHolyLightPDamage = (SpHolyLightPDamage + (((Real((Max HP of (Target unit of ability being cast)))) - (Life of (Target unit of ability being cast))) x 0.15))
      • -------- Heal --------
      • Set VariableSet SpHealAmount = SpHolyLightPDamage
      • Set VariableSet SpHealSource = DamageUnitTrigger
      • Set VariableSet SpHealTarget = (Target unit of ability being cast)
      • Trigger - Run Heal <gen> (checking conditions)
      • Set VariableSet SpDivineAegisBool = Wahr
  • Heal
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (SpHealTarget is alive) Equal to Wahr
          • (Percentage life of SpHealTarget) Not equal to 100.00
        • Then - Actions
          • Set VariableSet SpHealText = |cff00ff00+
          • Custom script: call ArcingTextTag.create(udg_SpHealText + I2S(R2I(udg_SpHealAmount)) + "|r", udg_SpHealTarget)
          • If ((Max life of SpHealTarget) Less than ((Life of SpHealTarget) + SpHealAmount)) then do (Set VariableSet SpHealAmount = ((Max life of SpHealTarget) - (Life of SpHealTarget))) else do (Do nothing)
          • Unit - Set life of SpHealTarget to ((Life of SpHealTarget) + SpHealAmount)
          • -------- --- --------
          • Set VariableSet MB_Healed[0] = (MB_Healed[0] + SpHealAmount)
          • Set VariableSet MB_HealedTotal[0] = (MB_HealedTotal[0] + SpHealAmount)
          • Set VariableSet MB_Healed[(Player number of (Owner of SpHealSource))] = (MB_Healed[(Player number of (Owner of SpHealSource))] + SpHealAmount)
          • Set VariableSet MB_HealedTotal[(Player number of (Owner of SpHealSource))] = (MB_HealedTotal[(Player number of (Owner of SpHealSource))] + SpHealAmount)
          • -------- --- --------
          • Set VariableSet SpHealAmount = 0.00
          • Set VariableSet SpHealSource = No unit
          • Set VariableSet SpHealTarget = No unit
        • Else - Actions

Variable.PNG


Variable1.PNG


Does it have anything to do with the fact that it is all written in a library or a function?
 
Level 39
Joined
Feb 27, 2007
Messages
5,016
Because you are modifying a Zinc resource, you do not need the "set" or "call" keywords for any lines. I don't really know how Zinc's precompiler works so writing them in manually like you have done might produce an error or .j file that crashes when it reaches this function because it encounters something like set set MB_Healed....

Why are you using two different arrays and then also storing data in the 0th index of both of those arrays? How are Healed and HealedTotal different? They are being set the same way. You should only need to have the last of your 4 variable setting lines:
JASS:
    function onHeal()->boolean{
        unit u=udg_HeroShadowhunter;
        real d=Chain_LastDamage;
        udg_MB_HealedTotal[GetConvertedPlayerId(GetOwningPlayer(u))] = udg_MB_HealedTotal[GetConvertedPlayerId(GetOwningPlayer(u))] + d;
        //BJDebugMsg(GetUnitName(u)+" was healed for "+R2S(d)+"!");
        return false;
    }
 
Last edited:
Level 12
Joined
Jan 10, 2023
Messages
191
In function OnHeal, I'm wondering about this line:
JASS:
   real d=Chain_LastDamage;

is it possible that 'Chain_LastDamage' has no value? I'm guessing it's a global given value elsewhere, but wondering if that's where the problem is coming from ?
 
Last edited:
Level 2
Joined
Jul 21, 2020
Messages
14
Thank you very much, now it works, I used the wrong variable, I should have used "d=Chain_LastHeal" and I can leave out the "set".

JASS:
//! zinc
library HealingWave requires ChainSys{

    function onCondition()->boolean{
        return GetSpellAbilityId()=='A0DG';
    }
    
    function onHeal()->boolean{
        unit u=udg_HeroShadowhunter;
        real d=Chain_LastHeal;
        udg_MB_Healed[0] = ( udg_MB_Healed[0] + d );
        udg_MB_HealedTotal[0] = ( udg_MB_HealedTotal[0] + d );
        udg_MB_Healed[GetConvertedPlayerId(GetOwningPlayer(u))] = ( udg_MB_Healed[GetConvertedPlayerId(GetOwningPlayer(u))] + d );
        udg_MB_HealedTotal[GetConvertedPlayerId(GetOwningPlayer(u))] = ( udg_MB_HealedTotal[GetConvertedPlayerId(GetOwningPlayer(u))] + d );
        return false;
    }

    function onFilter()->boolean{
        return !IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE);
    }



    function onAction(){
        unit u = GetTriggerUnit(),
        t = GetSpellTargetUnit();
        integer l=GetUnitAbilityLevel(u,'A0DG');

        real F = udg_SpHealingWaveFlatt;
        real FF = udg_SpHealingWaveFlattF;
        real P = udg_SpHealingWavePercent;
        real PF = udg_SpHealingWavePercentF;
        real S = I2R(GetHeroStatBJ(bj_HEROSTAT_INT, u, true));
        real a = ( ( ( F * l ) + FF ) + ( S * ( ( l * P ) + PF ) ) );
        
        boolexpr b=Filter(function onFilter);
        Chain_HealingWave(u,  //Caster
        t,               //Target
        a,                  //Heal
        ((1.0*l)-10.0)*0.01,  //Heal Reduction
        500.0,                //Radius
        (1*l)+2,              //Max Bounces
        0.33,                 //Bounce Intervals
        false,                //Doesn't Hit Caster
        b,                    //Target Filter
        function onHeal);     //Triggered Impact
        ClearTextMessages();

    }

    function onInit(){
        trigger t=CreateTrigger();
        TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT);
        TriggerAddCondition(t,Condition(function onCondition));
        TriggerAddAction(t,function onAction);
        t=null;
    }        
}
//! endzinc


I need the global variables for the multiboard. MB_Healed[#] is reset to 0 after each round, MB_HealedTotal[#] is not.

Multiboard.PNG
 
Status
Not open for further replies.
Top