Passing Variable Values between functions

Aniconic

I am the very model of a modern major general!
Reaction score
3
Hey guys, I'm currently trying to learn the syntax for jass, and I've been playing around with functions. I know how they work, I just have to get syntax down. :]

which brings me to my question: How do you pass local variable values between functions? Whats the correct syntax? :\
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Well, there is no way to directly do this, but (Depending on how you're gonna use it) I'd recommend using globals if you're not gonna use a wait inbetween the function calls...
 

hgkjfhfdsj

Active Member
Reaction score
55
there are few ways, and it depends on the use
for example
- passing data in timers involves using attachment systems such as Key Timers, TimerUtils or Hashtable for vanilla jass users
- passing to group filters etc involves setting either the value or a struct (vjass) to a global
- passing to another normal function involves including the appropriate arguments

these are very general ways, and as i said before it depends on how you use these data and the situation is.
 

Aniconic

I am the very model of a modern major general!
Reaction score
3
Wow, you can't just pass values then huh? :\ Thats lame. I just wanted to pass an integer value that stored the owner of the casting unit's player number in use with indexing global unit group and point variable arrays in a spell. Would have made my life a bit easier to not have to declare the same value multiple times, but its not life or death.

Thanks for the quick responses guys!
 

Aniconic

I am the very model of a modern major general!
Reaction score
3
well... you can callback that function and set the value for some member

example:

JASS:

function Testing takes integer i returns nothing
    call BJDebugMsg(I2S(i))
endfunction

function HeyHo takes nothing returns nothing
    local integer i = 120
    call Testing (i)
endfunction

Yes! that's exactly what I am talking about.

How would you do it that for a unit group function call though? I get errors if I try and run it like your example:
JASS:

function Group takes integer i returns nothing
    call UnitDamagePointLoc( GetSpellAbilityUnit(), 0.00, 100.00, udg_Temp_Point<i>, 100.00, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
    set i = 0
endfunction


function Trig_Untitled_Trigger_003_Actions takes nothing returns nothing
    local integer i
    set i = GetConvertedPlayerId(GetOwningPlayer(GetSpellAbilityUnit()))
    set udg_Temp_Point<i> = GetSpellTargetLoc()
    set udg_Damaged_Units<i> = GetUnitsInRangeOfLocAll(150.00, udg_Temp_Point<i>)
    // Here is the unit group function call
    call ForGroupBJ( udg_Damaged_Units<i>, function Group (i))
    call DestroyGroup( udg_Damaged_Units<i>)
    call RemoveLocation( udg_Temp_Point<i>)
    set i = 0
endfunction</i></i></i></i></i></i></i>
 

hgkjfhfdsj

Active Member
Reaction score
55
im pretty sure you can use [ljass]GetConvertedPlayerId(GetOwningPlayer(GetSpellAbilityUnit()))[/ljass] in function Group. (i could be wrong). otherwise set i as global since theres no wait
 

Laiev

Hey Listen!!
Reaction score
188
you can't pass argument in this way..

use something like set unitvariable = FirstOfGroup(whichGroup) and damage that unit if is enemy or what ever you need to check
 

Aniconic

I am the very model of a modern major general!
Reaction score
3
im pretty sure you can use [ljass]GetConvertedPlayerId(GetOwningPlayer(GetSpellAbilityUnit()))[/ljass] in function Group. (i could be wrong). otherwise set i as global since theres no wait

Yeah you can, I was just curious because I figure it would be easier to not have to worry about re-declaring values.

Here is what my code Finally Looks like. Anyone See any leaks? :]
JASS:

function Trig_Untitled_Trigger_003_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == &#039;A001&#039; ) ) then
        return false
    endif
    return true
endfunction

function Group takes nothing returns nothing
    local integer i = GetConvertedPlayerId(GetOwningPlayer(GetSpellAbilityUnit()))
    set udg_Temp_Point<i> = GetUnitLoc(GetEnumUnit())
    call UnitDamageTargetBJ( GetSpellAbilityUnit(), GetEnumUnit(), 200.00, ATTACK_TYPE_PIERCE, DAMAGE_TYPE_NORMAL )
    call AddSpecialEffectLocBJ( udg_Temp_Point<i>, &quot;Abilities\\Weapons\\Rifle\\RifleImpact.mdl&quot; )
    set i = 0
endfunction


function Trig_Untitled_Trigger_003_Actions takes nothing returns nothing
    local integer i
    set i = GetConvertedPlayerId(GetOwningPlayer(GetSpellAbilityUnit()))
    set udg_Temp_Point<i> = GetSpellTargetLoc()
    set udg_Damaged_Units<i> = GetUnitsInRangeOfLocAll(150.00, udg_Temp_Point<i>)
    call ForGroupBJ( udg_Damaged_Units<i>, function Group)
    call DestroyGroup(udg_Damaged_Units<i>)
    call RemoveLocation(udg_Temp_Point<i>)
    set i = 0
endfunction


//===========================================================================
function InitTrig_Untitled_Trigger_003 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_003 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Untitled_Trigger_003, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Untitled_Trigger_003, Condition( function Trig_Untitled_Trigger_003_Conditions ) )
    call TriggerAddAction( gg_trg_Untitled_Trigger_003, function Trig_Untitled_Trigger_003_Actions )
endfunction
</i></i></i></i></i></i></i></i>
 

Laiev

Hey Listen!!
Reaction score
188
>> Here is what my code Finally Looks like. Anyone See any leaks? :]

no

and this is like converted gui
 

Aniconic

I am the very model of a modern major general!
Reaction score
3
and this is like converted gui

I converted a basic GUI trigger with an event and a condition i knew i wouldn't be messing with, then wrote in the actions myself. I'm still learning syntax, figured that would be the easiest way to learn.
 
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