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

local udg_

local udg_

Presented by -Kobas-

This cool trick can be used in many programming languages and jass is one of them.
Shadowing variables, as named, allow us to use global variables created in GUI variable
editor as jass local variables in our triggers. This way we can create MUI code really
easy using Custom script command line (trigger action).

Honestly this is something useful only for GUI coders these days. People who code jass
or any other "version" of it (vjass, vrust etc) already have local variables as well as many
other things on their disposal.

So for all you GUI coders out there this resource should show you how to easily create
MUI code using this trick. All you need to know (will try to explain this in the most simple
way) are next few steps:

JASS:
Your new MUI trigger
-> Events
-> Conditions
-> Actions
          1. Local variables initialization //<- NEW
          2. Regular code
          3. Memory leaks cleanup //<- NEW

  • test1
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Avatar
    • Actions
      • Custom script: //-------------- Local variables setup --------------//
      • Custom script: local unit udg_local_Unit
      • Custom script: //-------------- Trigger code --------------//
      • Set local_Unit = (Triggering unit)
      • Hero - Modify Strength of local_Unit: Add 1000
      • Wait 60.00 seconds
      • Hero - Modify Strength of local_Unit: Subtract 1000
      • Custom script: //-------------- Memory leaks --------------//
      • Custom script: set udg_local_Unit = null

Test map has 2 more examples and all documentation required for you to go play with
this new method.

Notice: GUI variables are not same once you convert them to jass.

Example: FloatingText isn't
  • Custom script: local floatingtext udg_variable_name
instead it will be
  • Custom script: local texttag udg_variable_name
you can easy see that once converted to jass
JASS:
floatingtext // isn't highlighted
texttag // is

All this is explained in test map in BASIC part of examples.
For those who want to know more or already handle custom script with easy I have
added ADVANCED part with 2 examples, where is 1st just there for education purpose
(really simple one).


Keywords:
GUI, MUI, local, custom script, -Kobas-, ♥
Contents

local udg_ (Map)

Reviews
22:29, 6th Jul 2014 PurgeandFire: Useful.
Pretty much a good one, but ain't it's better as a tutorial with the map attached at the end? (Unless there's some exclusive codes in this system).
Was thinking about that as well, but somehow I see it more presented globally here, more people will find it here.
Also dunno how good it is as tutorial.
 
Level 5
Joined
Jan 27, 2014
Messages
164
Pretty surprised there isn't any pseudo local 'tutorial' in Hive yet. Or is there...?

Perhaps you could mention that the pseudo local method can only work for a single global variable.

Also, pseudo locals do not really work in GUI condition block. This can easily be solved by globalising the local again.
 
Pretty surprised there isn't any pseudo local 'tutorial' in Hive yet. Or is there...?

Perhaps you could mention that the pseudo local method can only work for a single global variable.

Also, pseudo locals do not really work in GUI condition block. This can easily be solved by globalising the local again.

Yeah any GUI code that split function (conditions for example) won't work here.
Will show way around as you mentioned.

Thanks.
 
how about variable with array?
if it's integer array named udg_i then, can it work with local integer array udg_i?
I'm noob, so much question in my head :3
Jass New Gen throw error, saying you can't use that name (it's already taken).
You can use custom jass variable (that will be fine) but you can use this variable in GUI, like you do with udg_ variables where you click on blocks and shit.
You will need to stick with custom script in this case.
 
Very funny test map, enjoyed watching all explode. :d

I think it would be good also to make test triggers leakless, since you clean locals, but you leak globals. (locations/effects)

Apart from if this is right place in spell section or not, this might be useful. And it's good that you created a long list with custom script examples.

What maybe would meaningful to note is that "TriggeringUnit" and "DyingUnit" already can be treatet like local, and so no extra local variables have to be created for them.
 
This is a cool trick ^^, it will help some people get out of the trouble with JASS & GUI compiler...

Jass New Gen throw error, saying you can't use that name (it's already taken).
You can use custom jass variable (that will be fine) but you can use this variable in GUI, like you do with udg_ variables where you click on blocks and shit.
You will need to stick with custom script in this case.

Check the map below, why I can local them ? >.<

  • Dash
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Custom script: local integer udg_II = 0
      • Custom script: local unit array udg_U
      • Custom script: local integer array udg_I
      • -------- ---------------------------------- --------
      • Set II = (II + 1)
      • Set I[II] = (Random integer number between 1 and 100)
      • Set U[II] = (Triggering unit)
      • Set II = (II + 1)
      • Set I[II] = (Random integer number between 1 and 100)
      • Set U[II] = (Triggering unit)
      • Set II = (II + 1)
      • Set I[II] = (Random integer number between 1 and 100)
      • Set U[II] = (Triggering unit)
      • Set II = (II + 1)
      • Set I[II] = (Random integer number between 1 and 100)
      • Set U[II] = (Triggering unit)
      • Set II = (II + 1)
      • Set I[II] = (Random integer number between 1 and 100)
      • Set U[II] = (Triggering unit)
      • Set II = (II + 1)
      • Set I[II] = (Random integer number between 1 and 100)
      • Set U[II] = (Triggering unit)
      • Set II = (II + 1)
      • Set I[II] = (Random integer number between 1 and 100)
      • Set U[II] = (Triggering unit)
      • Set II = (II + 1)
      • Set I[II] = (Random integer number between 1 and 100)
      • Set U[II] = (Triggering unit)
      • Set II = (II + 1)
      • Set I[II] = (Random integer number between 1 and 100)
      • Set U[II] = (Triggering unit)
      • Set II = (II + 1)
      • Set I[II] = (Random integer number between 1 and 100)
      • Set U[II] = (Triggering unit)
      • For each (Integer A) from 1 to II, do (Actions)
        • Loop - Actions
          • Game - Display to (All players) for 30.00 seconds the text: (String(I[(Integer A)]))
          • Game - Display to (All players) for 30.00 seconds the text: (Name of U[(Integer A)])
          • Set U[(Integer A)] = No unit
 

Attachments

  • Test.w3x
    16.7 KB · Views: 147
This is really nice.. so if I use this method the variable will be locally created but you can use the variable as a normal GUI variable? (in the trigger it is created that is.)
Exactly. :)
And you can use same variable in many triggers. :)

This is a cool trick ^^, it will help some people get out of the trouble with JASS & GUI compiler...
Check the map below, why I can local them ? >.<
You can't define arrays like this, compiler will throw error.
 
Deathismyfriend tutorial talk about this.
Also I truly think this belongs more to tutorial section ^^
Yeah it's something that is well known for several years now, but still dunno why,
when I explain this to GUI users in Triggers & Script forum section for example,
people have no idea what am I talking about...

Programmers that know jass won't have much of use of this and jet they know
about this, but GUI coders that should benefit and exploit this, have no idea.

I have updated resource with suggestions you guys posted and added extra
"chapter" for those who want to know more and use custom script to create
functions and shit.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
I'm often use this as laziness to make a proper MUI syndrome kicks in.
But I never thought it would be posted as a... resource ?

I'd highly suggest it should be posted in the tutorials section or some sort.
Afraid it will not famous ?

Don't worry !
Link it in your signature OR ask for it to be sticky-ed :)

Again, this should be tutorials for both beginner and intermediate triggerer, I mean method like this doesn't get exposed to public I guess.
 
So, is this recommended ? It is risky ? Will it cause desyncs ?
Personally, I never had any problems with this. But I left warning just in case.

If you want to keep things extra safe, each time you save map save it as
new one or switch between few saves. I do this mostly because problems like,
losing electric power while saving map (making map damaged in process).
 

Kazeon

Hosted Project: EC
Level 34
Joined
Oct 12, 2011
Messages
3,449
Personally, I never had any problems with this. But I left warning just in case.

If you want to keep things extra safe, each time you save map save it as
new one or switch between few saves. I do this mostly because problems like,
losing electric power while saving map (making map damaged in process).

damn true! I also did that...
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
First of all I'm not really a fan of shadowing global variables.

Basically there is no wrong information in the map file and the presentation is also good.
Some rumors say waits can be troublesome for multiplayer seasons, which I can't comment on because I never used this technique.

I'll need the opinion of another mod to make a final descision.
 
Top