• 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.

[JASS] Dangerous or just bad practice?

Status
Not open for further replies.
Level 2
Joined
Sep 1, 2007
Messages
12
Please read all the way thru. I do not want trigger help; rather, the safety concern I have with a certain way to pass data.

When i made a spell and re-analyze it for improvements, i decided that the best way to pass my data, that i received from the condition function, is to use a global variable.

Take a look at the script at the bottom.
Pay close attention to how <DATA> is being pass from MyCondition to MyAction.

JASS:
-------------------------------------------------------------------------
globals
    integer DATA = 0
endglobals
-------------------------------------------------------------------------
function MyCondition takes nothing returns boolean
//local integer i = GetSpellAbilityId()

    //if i == <Some Number> then
        set DATA = 1
        //return true
    //endif

//return false
endfunction
-------------------------------------------------------------------------
function MyAction takes nothing returns nothing
local integer i = DATA
//call DisplayTextToForce( Players(0), I2S(i))
endfunction
-------------------------------------------------------------------------
function MyTrigger takes unit a returns nothing
//local trigger t = CreateTrigger()
//call TriggerRegisterUnitEvent( t, a, EVENT_UNIT_SPELL_EFFECT)
//TriggerAddCondition( t, Condition( function MyCondition))
//TriggerAddAction( t, function MyAction)
//set t = null
endfunction


Assumming that no unit activate the script in exactly the same moment and that <DATA> main purpose is a one-time-usage/link, then is the method, that i decided on, safe from unintended-global-override? Also, <DATA> will not be used for any other trigger other than its associated condition and action functions.

Right now, I'm assuming its safe... since its unlikely that any two unit will activate the script at the exact same moment. And that, the only possible way to get such an accurate and reliable timing is to synchronize the trigger.
 
Level 7
Joined
Oct 5, 2007
Messages
118
And nethertheless, also if two units cast at exact same moment, the global wouldn't be overwrited, cause: A computer can only do first things first. Also a multi-core system isn't able to overwrite... otherwise the whole system would be chaos.
 
Level 11
Joined
Feb 18, 2004
Messages
394
the game script executes on a single path (thread) until it reaches a wait, a new thread (ExecuteFunc, ext), or an end of thread (the function which started the thread returns). Triggers are executed as conditions->actions. (only executing actions if all conditions are true, but all conditions will be evaluated even if the first one evaluated returns false. (according to vex))
 
Status
Not open for further replies.
Top