• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Saving Variables

Status
Not open for further replies.
Level 3
Joined
Jul 14, 2007
Messages
34
Hey, I was wondering if there is a way to save a variable for use in another function while it's in the same trigger; here's how it's set up.
JASS:
function whatever1 takes nothing returns nothing
    does something (Required Variable Here)
endfunction

function whatever2 takes some stuff returns nothing
    does stuff
    Acquires variable here (ex. angle = GetAngleBetweenPoints(localpointa,localpointb) )
endfunction

any help would be greatly appreciated, also; is there any additional cleaning that would have to be done to prevent leaks created by "saving" the variable?
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
JASS:
function whatever1 takes real angle returns nothing
     //do something with angle
endfunction

function whatever2 takes some stuff returns nothing
    local real angle
    //stuff
    set angle = GetAngleBetweenPoints(localpointa,localpointb )
    call whatever1(angle)
endfunction
This is how you pass variable from one function to another.
If you want you whatever1 function to be static(take nothing), maybe being a callback function (for a timer for example) you have bumped in the biggest problem in triggering.
Various methods have been developed to do this.
The really basic one is Handle Variables.
Then there come struct attachment systems.
CSData/CSsafety and all the other neat stuff from Vexorian.
P.s. You can search for there in the jass resource section/spell section/tutorials and in http://www.wc3campaigns.net/
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
The very same reason most people move from GUI to pure Jass:
Because people want MUI :D
 
Level 3
Joined
Jul 14, 2007
Messages
34
Here, I'll post the JASS, and yea it needs to be MUI.
I'm using Vexorian's CS to create collision missiles and the Knockback function by Silvenon until I understand structs and such enough to create my own.

I know I haven't removed leaks yet, I'm just trying to get it to work right now; the knockback never knocks it back at the right angle.

Right now the function tells it to get the angle between the missile and impacted unit, and to send the unit flying at that angle (In radians because that's what the knockback function uses) but it doesn't send them at the right angle most of the time, anyone see what's wrong with it? I was wondering how to save to move the angle that I send the collision missile at and knock them back in the same direction since it seemed simpler, but away from the exploding collision missile would be better if someone can spot what's wrong.

Knockback function takes unit knocked back, speed, angle, and duration.

JASS:
function Trig_ForceBall_Conditions takes nothing returns boolean 
    return GetSpellAbilityId() == 'A000' 
endfunction

function OrbKnockback takes nothing returns nothing 
    local unit h = GetTriggerUnit()
    local location htuloc = GetUnitLoc(h)
    local unit cm = GetTriggerCollisionMissile()
    local location clmloc = GetUnitLoc(cm)
    local real ang = DEG2RAD(AngleBetweenPoints(htuloc,clmloc))
    call Knockback(h,250,ang,1)
    call CollisionMissile_Destroy(cm)
    set h = null
    set cm = null
 
endfunction

function Trig_ForceBall_Actions takes nothing returns nothing
    local unit ucast = GetTriggerUnit()
    local location ucastloc = GetUnitLoc(ucast)
    local real casterlocx = GetLocationX(ucastloc)
    local real casterlocy = GetLocationY(ucastloc)
    local location targetloc = GetSpellTargetLoc()
    local real targetlocx = GetLocationX(targetloc)
    local real targetlocy = GetLocationY(targetloc)
    local real casterlook = GetUnitFacing(ucast)
    local real angbtwp = AngleBetweenPoints(ucastloc,targetloc)
    local location createloc = PolarProjectionBJ(ucastloc,10,angbtwp)
    local real hypotn = SquareRoot(((targetlocx - casterlocx) * (targetlocx - casterlocx)) +((targetlocy - casterlocy) * (targetlocy - casterlocy)))
    call CollisionMissile_CreateLoc("Abilities\\Weapons\\DemonHunterMissile\\DemonHunterMissile.mdl",createloc,angbtwp,800,0,1000,50,false,50,function OrbKnockback)    
endfunction

//===========================================================================
function InitTrig_ForceBall takes nothing returns nothing
    set gg_trg_ForceBall = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ForceBall, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_ForceBall, Condition( function Trig_ForceBall_Conditions ) )
    call TriggerAddAction( gg_trg_ForceBall, function Trig_ForceBall_Actions )
endfunction
 
Status
Not open for further replies.
Top