Tutorial Local variables in GUI

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Introduction

Have you ever made a spell, what uses lots of waits or loops, involving several dummy units? Have you ever wondered why it messes up and is only usable by one hero per a map? If yes, this tutorial will explain, why this is like so and show possible solutions to your porblem.

Before we can get started, I will explain a few acronyms and words, that I will be using later to explain further details.

MUI (Multi Unit Instanceable)

Generally associated with spells. It means more than one unit can cast a trigger enchanced spell at the same time, without interfering the other unit. (without interfereing the triggers actions)

Global variable


A variable, which holds information (depends on the type of the variable), what can be used in all functions.

Local variable

A variable, which holds information, but it can only be used in the function it was created in. (A local variable, however, can be used in other functions aswell, while still being local, with the help of Kattana’s Handle Variables or with Vexorians Caster System.)

(Kattana’s Handle Variables
http://www.wc3jass.com/viewtopic.php?t=224

Vexorians Caster System
http://www.wc3campaigns.net/showthread.php?t=80534)

Lets get started!


The easiest way to make a spell mui, is using ‚triggering unit’ instead of casting unit. Every time a trigger is run, it has it’s own triggering unit. Besides, casting unit unstable, it tends to get lost after waits.

Example #1

exmaple1.gif


An ability is cast and the casting unit should get a new ability for 30 seconds. But what will happen, if another unit casts the ability? The casting unit gets overridden. Besides, casting unit gets lost after waits, especially after long one. The final result would be that the ability never gets removed.

How to solve it?

exmaple1_a.gif


Replace the casting unit with triggering unit, because casting unit is actually the triggering unit.

The prior – declaring local variables in GUI.


But, what to do, if I have more than one unit used by a spell, which needs to be local?

The solution is tricking the World Editor to think a global variable (which holds the value of your unit) is a local one.

How can I do that?

You have to use the ‚custom script’ action.

Remember:


Local variables are always declared in the beginning of a function.

Every local variable has to be nulled in the end of a function, execpt a real, an integer, a boolean or a string local variable.

Global variables have udg_ prefixes.

The syntax for declaring local variables.
Custom Script : local variable type variable name

Example #2

How to declare a local global variable in GUI.

Lets say you need the TmpUnit and TmpPoint to be local. The declaration would be following.

example2.gif


As you can see, the point variable is called location variable in JASS. There are more differences. Here is the list of the most used variable types. (JASS is case-sensitive)

I shall remind the syntax one more time.

local variable type variable name

World Editor variable type name======>Real variable type name

(Why in the world I cannot use TAB?)

Boolean=======================>boolean
Destructible====================>destructable
Floating Text===================>texttag
Integer=======================>integer
Item=========================>item
Player========================>player
Player Group===================>force
Point=========================>location
Real=========================>real
Region=======================>rect
Sound=======================>sound
Special Effect=================>effect
Lightning=====================>lightning
String=======================>string
Terrain Deformation=============>terraindeformation
Timer=======================>timer
Timer Window=================>timerdialog
Ubersplat====================>ubersplat
Unit========================>unit
Unit Group===================>group

To pull the loose ends together, I have to mention that one cannot use local global variables in unit groups, if/then/else’s and in ‘for each integer a do multiple action’ loops, because blizzard programmed them to be separate functions and local variables cannot be transferred between functions. (Without the help of the above-mentioned systems, of course. But that is JASS playground.)
Also only one variable per type can be overriden and local arrays don't override global ones.

Have fun experimenting with local global variables!

PS: Please correct me, if I am wrong somewhere or if I have spelling mistakes. Feedback is always appriciated.
 

Master

Thou shall be helped by...The Black Adder!
Reaction score
72
Very nice (I read 50% of it, though).
Do you know what is funny? this was about to be my next tutorial...now I have to move on :p
 
W

wahoyaho

Guest
how did you set TmpPoint?

I can't see my local variables in the variables list
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
TmpPoint and TmpUnit are actually global variables, what you have to create in the variable editor. The custom script is needed to trick the Editor into thinking they are local variables.
 

The Big S

New Member
Reaction score
6
Just create a new variable point, and call it TmpPoint


If you already did that, then it should be there =/

EDIT: Hehe, sorry, didn't see your post before posting Andrew
 
Reaction score
456
I prefer to use JASS or GUI alone, not mixed. Altough a nice looking :p
You know what's funny... I'm writing with WII :p

Anyway, you didn't mention ubersplat in the list of different types of variables. (this is kinda slow way to write in forums..)
 

SFilip

Gone but not forgotten
Reaction score
634
Well if you make a local variable with the same name as some global it will override it in the function it was declared in.

This has two limits though:
-only one variable per type can be overriden - you can't, for example, have two "fake" locals of type unit
-local arrays don't override global ones from some reason
 

SFilip

Gone but not forgotten
Reaction score
634
Oh and almost forgot...
The "can be used in other functions aswell" with the handle variables and all can be quite misguiding. People usually don't know what a function is. If they do then they might just go for implementing local handle variables (or the caster system) somehow, somewhere thinking that this would make them able to use "fake" locals inside if..then..else and player/unit group enumerations. And, well, if they know that is not the case...then why the hell are they still using GUI? :p
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
To pull the loose ends together, I have to mention that one cannot use local global variables in unit groups, if/then/else’s and in ‘for each integer a do multiple action’ loops, because blizzard programmed them to be separate functions and local variables cannot be transferred between functions. (Without the help of the above-mentioned systems, of course. But that is JASS playground.)

I know. Global locals are for lazy people or people, who do not wish to learn JASS.:p
 

ayumilove

Youtube account suspended! youtube.com/ayumilove8
Reaction score
110
this tutorial not so useful, try teaching us how to use katana system or vexorian system, its much better compare to the one you have written up there.

in this way, more people will be introduce to their powerful system, and more people would use it, instead of relying the local variable in gui.

to me, i find it rather useless to have local variable with gui.

global is much better <3
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
>this tutorial not so useful, try teaching us how to use katana system or vexorian system, its much better compare to the one you have written up there.
>in this way, more people will be introduce to their powerful system, and more people would use it, instead of relying the local variable in gui.

Now, there is a problem. Handle Variable isn't local variables or global variables, it's a completely different thing :)
It's more of 'object variables', an object that owns it's own variables and are not sharing them with anything else.

>global is much better
Well, I understand that you aren't that serious with this :)
However, just for those who doesn't know. Globals aren't better than locals, and locals aren't better than globals. They are just two different tools for a programmer to use, using the wrong tool is bad but that doesn't mean that the tool is worthless.
 

Chocobo

White-Flower
Reaction score
409
Boolean=======================>boolean
Destructible====================>destructable
Floating Text===================>texttag
Integer=======================>integer
Item=========================>item
Player========================>player
Player Group===================>force
Point=========================>location
Real=========================>real
Region=======================>rect
Sound=======================>sound
Special Effect=================>effect
Lightning=====================>lightning
String=======================>string
Terrain Deformation=============>terraindeformation
Timer=======================>timer
Timer Window=================>timerdialog
Ubersplat====================>ubersplat
Unit========================>unit
Unit Group===================>group

Isn't it a bit too big..? You can simply put handle to all.


for each integer a do multiple action’ loops

Wrong. But you must use local loops to avoid Integer A/B overriding.


PS: Please correct me, if I am wrong somewhere or if I have spelling mistakes. Feedback is always appriciated.

Yes you did a weird one:

(Kattana’s Handle Variables


Maybe removed the sign?
 
M

Mythic Fr0st

Guest
hmm

Looks good, only read about 2% of it, but the big images of the triggers look good! lol (im not in a reading mood)
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
this tutorial not so useful, try teaching us how to use katana system or vexorian system, its much better compare to the one you have written up there.

That assumes one knows JASS above medium level, if reading a tutorial about handle variables or the caster system.
 

exge

New Member
Reaction score
15
this tutorial not so useful, try teaching us how to use katana system or vexorian system, its much better compare to the one you have written up there.

in this way, more people will be introduce to their powerful system, and more people would use it, instead of relying the local variable in gui.

to me, i find it rather useless to have local variable with gui.

global is much better <3

lol true
 

Cohadar

master of fugue
Reaction score
209
LoL those systems are outdated.

Kattana, Vexorian and Cohadar are using structs now :D
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top