• 🏆 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!

[Trigger] How to use locals?

Status
Not open for further replies.
Level 13
Joined
Jun 5, 2008
Messages
504
Im first time using locals and i have some problems. So i have few questions.

can there be unit and possition local in same trigger?

can there be multiple local units in same trigger?

can there be multiple possition locals in same trigger?

and with locals i mean like this:
  • Custom script: local unit udg_VA_caster
 
Level 13
Joined
Jun 5, 2008
Messages
504
I never use locals in GUI, so I can't be entirely sure, but it's possible in jass, so it should also be possible in GUI. Just put each local declaration under each others, at the top of the trigger. Besides, you could easily find out about this yourself by trying...

Well even if i try I dont know if it can be done if i cant do it. Thats why im asking. There is high possibility that I have failed to use it correctly.
 
Level 5
Joined
Aug 27, 2007
Messages
138
You can have as many locals as you want in a trigger and as many different types as you want, as long as they have different names and are declared at the beginning of a trigger.

  • Custom script: local unit udg_u
  • Custom script: local real udg_r
  • Custom script: local integer udg_i
  • Custom script: local unit udg_c
Locals are created and exist independently for each execution of the trigger. If a unit dies, a global variable is set to the unit-type of the dying unit and a unit of that type is created 20 seconds later, then, if three more units die in that twenty-second period, the unit created will be the last unit that died, if that makes any sense. Globals overwrite. Locals do not.

GUI can't really do locals in the real sense, but they can "fake it" by naming a local udg_yourglobalvariablename. Just make sure you null everything you use that's not an integer, real, string, or boolean, (the correct term is "handle" for these things) to prevent memory leaks, i.e.:

  • Custom script: set udg_u = null
  • Custom script: set udg_c = null
 
Level 5
Joined
Jan 15, 2007
Messages
199
I read somewhere that you could have only one "local global" variable per trigger.

Then you read wrong.

The custom script just inserts it into the jass, it dosnt cause any limitations, you can even do endfunction in custom script
 
Level 11
Joined
Apr 6, 2008
Messages
760
but really learn jass if u know how to use locals u know like 50% of jass

and convert trigger functions from GUI to jass to u know what they do e.g

if u wanna create a unit and u dont know the how to do it in jass

  • Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing (270.0) degrees
then convert it to custom text, it would look like

JASS:
call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), GetRectCenter(GetPlayableMapRect()), bj_UNIT_FACING )

and GUI structure is

  • Trigger
    • Events
    • Conditions
    • Actions
but jass is

  • Trigger
    • Actions
    • Conditions
    • Events
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Guys, Marcelo Hossomi is right.

It has nothing to do with the fact you're using a local, it's to do with the overwrite hack where a local overwrites a global or a parameter (global in this case, of course).

It causes some weird behaviour - I believe they all act as one variable in a sense, by means of an H2I-I2H-like conversion which occurs.

@Ciebron, as for your "Jass structure" 'diagram', "Trigger" (not trigger) in Jass is more of a container than an actual thing that does anything. There is no required structure except for InitTrig, which is eliminated in vJass.
 
Status
Not open for further replies.
Top