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