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

[Trigger] question

Status
Not open for further replies.

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
hi,

using gui and customtext

if i make a udg_variable a local
it become a local variable and can go through wait unchanged...
but does the variable keep its local function if extended to another trigger?

ex: trigger a
customtext: local udg_variable
set variable = 12
run trigger b (ignoring condition)

trigger b
display to player(variable) : "variable value is " + I2S(variable)

is the variable in trigger b, a local variable? or does it loose its localness when extended to another trigger using the trigger run function?

because if i use (attacking unit) with event unit is attacked,
every extended trigger will still have the same event from the base trigger and (attacking unit) will work in all of them.... so what about local? do they stay local when extended?
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
well i don't really understand...

if you do
Trigger A event: a unit die
run trigger B
run trigger C
run trigger D

Trigger B event: none
display name of (dying unit)

Trigger C event: none
display maxlife of (dying unit)

Trigger D event: none
wait 2.00
replace (dying unit) with (unittype of (dying unit)) with max life and mana

what do you mean the variable is global? it use a function call to get the value.
a global cannot keep after a wait, because it get over written if another unit die before wait end.

so you mean you sure that any global set to local will be only local while they are in the origin trigger?
and when i run other triggers from the origin trigger they keep their value because they are global but they loose their local function and can be over written if wait occur?
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
no this will not work
the reason being how local variable works, locals wont get transitted to another trigger, they may not work even in the same trigger under certain circumstances
the thing is, when you call function, the local variable is created between the function and endfunction and you can only use this variable in that scope, in this case function.
If you run other trigger it will not transfer the variable because the trigger runs totally different functions
Also when I say in the same, if you do pick every unit in group, you are actually calling new function so if you did:
  • test
    • Events
    • Conditions
    • Actions
      • Custom script: local integer i = 0
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • Custom script: call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, I2S(i))
when you try to compile it, it will pop syntax error, because the real code is something like this:
JASS:
function Trig_test_Func002A takes nothing returns nothing
    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, I2S(i))
endfunction

function Trig_test_Actions takes nothing returns nothing
    local integer i = 0
    call ForGroupBJ( GetUnitsInRectAll(GetPlayableMapRect()), function Trig_test_Func002A )
endfunction

//===========================================================================
function InitTrig_test takes nothing returns nothing
    set gg_trg_test = CreateTrigger(  )
    call TriggerAddAction( gg_trg_test, function Trig_test_Actions )
endfunction

and yes the group will leak

by the way, the running trigger with Dying unit will not work because Dying unit only returns value if the Event has something to do with Units(either Generic or Specified unit), with no effect you have no unit
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
but it do work...
i don't mean the local but the (dying unit)

if a trigger with event run another trigger he somehow get the other trigger event...
i am not sure if what i say is correct...
but i merged all trigger which used same event, but then i had to split it because it was huge, so it became like:

unit die
if dying unit = a, b, c, d, e, f, g, h, i
run trigger 1
if dying unit = j, k, l, m, n, o, p, q, r
run trigger 2
if dying unit =s, t, u, v, w, x, y, z, 0
run trigger 3

trigger 2
if dying unit = j, k, l
do remove dying unit
if dying unit = m, n, o, p
do set life of killing unit to life of killing unit + 10
remove dying unit
if dying unit = q, r
remove killing unit from game
replace dying unit with unittype of dying unit

1)these work fine, so the event is transfered to other trigger
No?


2)also another question what happen to a global variable that has become local inside a trigger with
customtext: set local integer udg_variable
does the global variable change or just a local inside the trigger?
if so then other trigger depending on the value from local will bug because they will only retrieve the global value wich didn't change?

3) what happen when you use global variable that are launched in multiple trigger by same event?
trigger 1
unit die
if unittype= a, b, c, d
set Tempunit = dying unit

trigger 2
unit die
set Tempunit = killing unit

trigger 3
unit die
if unittype=0, 1, 2, 3
set Tempunit = dying unit
else
set Tempunit = killing unit

what would happen to Tempunit?
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
1) actually, it works and Im very suprprised, I thought it didnt work
2) no the global is still global but making a local variable with the same name as global one is only to allow GUI related stuff to work with no custom text, inside the function you have to local variable will be used the local's data, outside you will use the globals data
3) depends on which trigger runs first, and Im not sure how WE does the ordering so the result will most likely be random everytime
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
i see....
that's why i have no choice but to use the function (attacking unit)
putting a variable with the number of triggers involved is bound to create bug, wich it allready did, and try to use local to remove bug from variable is no solution either because the trigger overlapse with each others running other trigger and also using group function, so local wouldn't work correctly...

thanks for your answers edo494
i know what is left for me to do now :p
 
Status
Not open for further replies.
Top