Post by Max on Jul 11, 2005 13:48:18 GMT 1
This tutorial will explain how variables work.
1. What is a variable?
A variable is something that can keep its value and can be used to store any value. Variables are used in triggers and they are necessery to make a good-working map. Only by variables you can tell a trigger which unit exactly you want use or which quest you mean.
When making quests (for example) you can refer to the Last created quest function, but that's only last quest. If you want to refer to another quest, you must use a varible. And that varible must be set by trigger Set variable and can look like:
Set MyQuestVariable = Last created quest
If you use this action after you create a quest, you'll be able to refer to that quest using MyQuestVariable until you change that varible.
2. How to create a variable?
In Trigger Editor you can find Variables under Edit section in toolbar.
Then the variable window opens...
Click on a green +x button to create a new variable.
Variable Name: Write here the name of the variable. It can be any, but it must be without a gap.
Variable Type: Select a variable type. For unit use Unit, for more units use Unit Group, For whole number use Integer and so on.
Array Will be explained later.
Initial Value: Initial value of some variables can be defined. This means that a variable will have its value defined from the begining of the map and it doesn't need to be set. But you can change them later if you want. It's same like using trigger Set variable but you can only define PRESETS and and only some VALUES as 'Initial values'. It's logical that you can't use FUNCTIONS and VARIABLES.
There are variables types that don't have their initial value (Visibility Modifier variable type has written grey None after Initial Value). Initial value of these types canot be set. Some variable types have their default value (booleans have false, integers have 0) while others don't (they have red None written after Initial Value). Unit unit variable type doesn't have default initial value, but you can define it by clicking on red None. You can only set No unit initial value.
Use this if you want a variable to have its value from the begining of the map.
Clear Value - if you click this button, the initial value of the variable will be deleted and replaced with none or default initial value.
3. How to use variables in triggers?
If you don't define initial value of a variable you can do it by triggers (you should set a value before using it in trgiggers). Trigger Set Variable will allow you to set the value of a varible during the mission. It's not initial value, and you can also use FUNCTIONS and other VARIABLES also as values.
Click on red Variable text and select a varible you want to set. If you select 'Integer' varible type you'll be able to set integer value by one of these:
VALUE - (most used) number (whole number - integers)
FUNCTION - (most used) there are many functions for integers like Hero - Hero Level - this functin returns an integer value (level of chosen hero)
VARIABLE - you can set a variable to have same value as another variable.
PRESET - Integers don't have presets.
4. Variable Arrays
If you check array option when creating a variable, the variable will have its index, so you'll be able to create more variables of same type at once.
Example:
If you have 4 Grunts and you want each to have his own Unit variable, create a variable ('Unit' variable type) with a name "Grunt" and check Array option. You can define the size of array (4), but you can set 20 - it's not very important.
You have created a variable array. Now how to use it:
There is a little difference when you use variable arrays in triggers. Triggers will also require Index of the variable array. Index in nothing but an integer (this can have very important use, but it's for experienced ones).
To set Grunt variable to each 4 Grunts use trigger Set Variable and in each use the Grunt variable. Then click on red Index and write 1-4 to each (or you can use 0-3).
The trigger will look like this:
ACTIONS:
Set Grunt[1] = ...
Set Grunt[2] = ...
...
I hope this tutorial helped. If you have ANY questions about variables or about this tutorial, or you just still don't know how variables work, post here!
1. What is a variable?
A variable is something that can keep its value and can be used to store any value. Variables are used in triggers and they are necessery to make a good-working map. Only by variables you can tell a trigger which unit exactly you want use or which quest you mean.
When making quests (for example) you can refer to the Last created quest function, but that's only last quest. If you want to refer to another quest, you must use a varible. And that varible must be set by trigger Set variable and can look like:
Set MyQuestVariable = Last created quest
If you use this action after you create a quest, you'll be able to refer to that quest using MyQuestVariable until you change that varible.
2. How to create a variable?
In Trigger Editor you can find Variables under Edit section in toolbar.
Then the variable window opens...
Click on a green +x button to create a new variable.
Variable Name: Write here the name of the variable. It can be any, but it must be without a gap.
Variable Type: Select a variable type. For unit use Unit, for more units use Unit Group, For whole number use Integer and so on.
Array Will be explained later.
Initial Value: Initial value of some variables can be defined. This means that a variable will have its value defined from the begining of the map and it doesn't need to be set. But you can change them later if you want. It's same like using trigger Set variable but you can only define PRESETS and and only some VALUES as 'Initial values'. It's logical that you can't use FUNCTIONS and VARIABLES.
There are variables types that don't have their initial value (Visibility Modifier variable type has written grey None after Initial Value). Initial value of these types canot be set. Some variable types have their default value (booleans have false, integers have 0) while others don't (they have red None written after Initial Value). Unit unit variable type doesn't have default initial value, but you can define it by clicking on red None. You can only set No unit initial value.
Use this if you want a variable to have its value from the begining of the map.
Clear Value - if you click this button, the initial value of the variable will be deleted and replaced with none or default initial value.
3. How to use variables in triggers?
If you don't define initial value of a variable you can do it by triggers (you should set a value before using it in trgiggers). Trigger Set Variable will allow you to set the value of a varible during the mission. It's not initial value, and you can also use FUNCTIONS and other VARIABLES also as values.
Click on red Variable text and select a varible you want to set. If you select 'Integer' varible type you'll be able to set integer value by one of these:
VALUE - (most used) number (whole number - integers)
FUNCTION - (most used) there are many functions for integers like Hero - Hero Level - this functin returns an integer value (level of chosen hero)
VARIABLE - you can set a variable to have same value as another variable.
PRESET - Integers don't have presets.
4. Variable Arrays
If you check array option when creating a variable, the variable will have its index, so you'll be able to create more variables of same type at once.
Example:
If you have 4 Grunts and you want each to have his own Unit variable, create a variable ('Unit' variable type) with a name "Grunt" and check Array option. You can define the size of array (4), but you can set 20 - it's not very important.
You have created a variable array. Now how to use it:
There is a little difference when you use variable arrays in triggers. Triggers will also require Index of the variable array. Index in nothing but an integer (this can have very important use, but it's for experienced ones).
To set Grunt variable to each 4 Grunts use trigger Set Variable and in each use the Grunt variable. Then click on red Index and write 1-4 to each (or you can use 0-3).
The trigger will look like this:
ACTIONS:
Set Grunt[1] = ...
Set Grunt[2] = ...
...
I hope this tutorial helped. If you have ANY questions about variables or about this tutorial, or you just still don't know how variables work, post here!