COMMAND PARAMETERS
This section explains how you can add parameters, and how you can use them when executing a command.
Adding Parameters
1. In the command inspector click the "+" button to add a new parameter. In Alternative you can click the "Add New" located at the bottom of the list.
2. Enter a name for the parameter.
3. Select the parameter type (See Parameter Types).
4. Check the Optional flag if this parameter is optional.
5. Add another parameter by clicking the "Add New" button, or click the "Update Code" button to recompile the command.
Using Parameters
To use a parameter simply add the '-' character in front of the parameter name, followed by its value:
The only exception to this are Immediate Parameters, that can be called directly without the '-' prefix (see Immediate Parameters).
Immediate Parameters
Immediate parameters are a special type of parameter that can be used without the '-' prefix and without providing a value for them.
To create an immediate parameter go to the command inspector and check the Immediate checkbox, this will show up the list of possible parameter options.
Use the "+" and "-" buttons to add or remove options and enter the values inside the input fields.
When you have finished setting up the parameter options, click the "Update Code" button as usual to recompile the command.
NOTE: there can be only one immediate parameter per command.
To use an immediate parameter simply type one of its options after the command:
Parameter Types
You can define different types for each parameter:
Parameter Type | Description | Usage Example | Notes |
---|---|---|---|
(Immediate) | Immediate string value that can be used like a switch in your command code | up, down, left, right | See Immediate Parameters |
None | A parameter without value, similar to Bool (true if defined, false if not) | -recursive -allowEnemies |
|
Bool | Boolean value | true, false (bool) true, false (string) 0, 1 |
|
Byte | Byte value in the range (0,255) | 0, 1 .... 255 | |
Char | Single character | a, b, 1, x, ! | |
Decimal | Decimal floating-point number | 23.56 | Use dot (.) as decimal separator |
Double | Double precision floating-point number | 23.56 | Use dot (.) as decimal separator |
Float | Single precision floating-point number | 23.56 | Use dot (.) as decimal separator |
Int | Integer value (32 bit) | 0, 1, 23, -56 | |
Long | Integer value (64 bit) | 0, 1, 23, -56 | |
Short | Integer value (16 bit) | 0, 1, 23, -56 | |
String | Character string | foo, bar, enemy_12 | No spaces allowed |
Vector2 | X,Y Vector | 1,2 -34.3,99.23 |
Use comma (,) to separate coordinates and dot(.) for decimal values |
Vector3 | X,Y,Z Vector | 1,2,3 -34,3,99.23,-56.67 |
Use comma (,) to separate coordinates and dot (.) for decimal values |
GameObject | Reference to a prefab object in the project | ID of the prefab* | *see GameObject Parameters |
Accessing Parameters from Code
When you generate the code of a command a series of function will be automatically added to access parameter values from your script.
The format is always the following:
Parameter_[PARAMETER_NAME]
You should check if the parameter has been passed to the command before using it. Standard usage patterns are the following:
// For Immediate parameter if(Parameter_Immediate != null) Echo("Immediate parameter is: " + Parameter_Immediate); // Example of a switch using an immediate parameter if(Parameter_Immediate != null) { switch(Paramater_Immediate) { case "up": MoveUp(); break; case "down": MoveDown(); break; case "left": MoveLeft(); break; case "right": MoveRight(); break; } } // Example of parameter of type None foreach(var gameEntity in gameEntities) { if(!gameEntity.IsEnemy() || Parameter_allowEnemy) gameEntity.RestoreAllEnergy(); } // Generic parameter usage if(Parameter_foo.HasValue) Echo("Value of foo is: " + Parameter_foo.Value); // Example of GameObject parameter if(Parameter_enemyPrefab != null) Instantiate(Parameter_enemyPrefab);
GameObject Parameters
GameObject parameters stores references to prefabs in your project, so you can access them from your command script (typically for instantiating new objects in the scene)
Each gameobject has a prefab id associated that you must pass to the command to access that specific prefab:
To access the prefab from your code, simply use the Parameter_X getter explained in the previous section.
// Spawning the selected enemy type // Parameter_enemyType will already contain the selected GameObject, you don't have to care about the prefab ID passed to the command. GameObject objToSpawn = this.Parameter_enemyType; GameObject.Instantiate(objToSpawn, Parameter_pos.Value, Quaternion.identity);