Variables (GUI)

From WarCraft3

< wc3
Jump to: navigation, search

Variables are used to store data in game which can be called later on and used to control data more efficiently. Like Jass, GUI supports variables. Unlike in Jass, however, there are only global variables in GUI. All variable types of Jass also aren't available in GUI. With all of this, also has the problem of memory leaks.

Contents

Creating variables

The Variable Editor

Variables in GUI are created using the Variable Editor, which can be opened by clicking the yellow X button or by using the hotkey Ctrl + B in the Trigger Editor. A new variable can be created in the Variable Editor by clicking on the green +X button, which will pop up a new window, asking you to specify the variable's name, type, initial value, whether it is an array, and the array size (the last one only when the variable is an array).

Using variables

Variables' values can be changed using the Set Variable action:

Actions-SetVariables.jpg Set My_Var = (1 + 72)

The first modifyable part (on the left of the = sign) is what variable will get a new value, and the second part (the part right from the = sign) is the value that will be put into that variable. The variable whose value is modified has to be determined first, because the possible values depend on the type of the variable - only values that share the type of the variable can be stored to the variable.

Using variables' values can be done by selecting the variable from the 'Variable:' list when selecting an value for a modifyable part of an action or a condition. Variables' values cannot be used in events (unless using the Trigger - Add New Event action). The events are registered at map initialization, so the variables used in events would only register the value of the used variable at map initialization unlike some GUI users think, which isn't usually of much use.

When using variables declared in the Variable Editor with the Custom Script action (or with Jass in general), the variables' names need to be prefixed with udg_. So for example a GUI variable called My_Var would be called udg_My_Var in custom script.

Variable Types

  • Ability
  • Attack Type
  • Boolean
  • Buff
  • Camera Object
  • Combat Sound
  • Damage Type
  • Destructible
  • Destructible-Type
  • Defeat Condition
  • Dialog
  • Dialog Button
  • Effect Type
  • Floating Text
  • Game Cache
  • Game Speed
  • Image
  • Image Type
  • Integer
  • Item
  • Item-Class
  • Item-Type
  • Leaderboard
  • Lightning
  • Lightning-Type
  • Multiboard
  • Order
  • Player
  • Player Color
  • Player Group
  • Point
  • Pathing Type
  • Quest
  • Quest Requirement
  • Race
  • Real
  • Rect
  • Sound
  • Sound Type
  • Special Effect
  • String
  • Tech-Type
  • Terrain Deformation
  • Terrain Shape
  • Terrain Type
  • Timer
  • Timer Window
  • Trigger
  • Ubersplat
  • Ubersplat Type
  • Unit
  • Unit Group
  • Unit-Type
  • Visibility Modifier
  • Weather Effect
  • Event
  • Trigger Condition
  • Trigger Action
  • Boolean Expression
  • Hero Skill
  • Event Id
  • Multiboard Item
  • Region
  • Trackable Object

Arrays

GUI variables also have an option to create an "array" of possible inputs. To change a variable to an Array type, click the box marked "Array". If done correctly, the box marked "Size" should become usable. When you change a variable to an array type, if it is already in use you will recieve a confirmation request to change the variable to an array; the reason for doing so is attributed to the fact that array variables are structurally different from regular variables.

Actions-SetVariables.jpg Set My_Var[1] = (1 + 72)
Actions-SetVariables.jpg Set My_Var[2] = (2 + 72)
Actions-SetVariables.jpg Set My_Var[3] = (3 + 72)

The number in the bracket corresponds to a possible input in your array. When a trigger is used to display My_Var[1], it will use (1 + 72). Likewise, for My_Var[2], it will use (2 + 72). This feature makes using 1 array variable preferable to creating numerous extra variables.

Size

Unlike the field 'Size' in the variable editor might suggest, arrays have a fixed size: 8192. This means you can use integers from 0 to 8191 (inclusive) inside the square brackets. There is no way of changing this size.

What the size field in the variable editor does is determine how many of the array's slots are initialized with the default value. For example if My_Var's default value is 8 and its size is 345, the slots with indexes from 0 to 345 (inclusive) will be initialized with the value 8, but the rest of the slots will have the default value of 0.

Common uses

Common applications of array variables:

  • Storing a number of heroes for a Random Hero Trigger
  • Storing player numbers (1 = Red, 2 = Blue, 3 = Teal) for use later.
  • Making abilities MUI in GUI by using an increasing number inside your brackets.
Personal tools