Variables and Lists
Creating and Managing Variables
Objective: Create and manipulate variables to store and retrieve data.
- Create a variable:
var set "Hello" greeting;
- "Hello" is the value to store.
- "greeting" is the variable name.
- Get a variable:
var get "greeting" message;
- "greeting" is the variable to retrieve.
- "message" is the new variable to store the value.
- Display the variable:
csl write message;
Working with Lists
Objective: Create and manipulate lists to work with data collections.
- Create a new list:
lst new myList;
- "myList" is the name of the list.
- Add items to the list:
lst set myList "0" "apple"; lst set myList "1" "banana";
- "0" and "1" are the indices.
- "apple" and "banana" are the values.
- Get an item:
lst get myList "0" fruit; csl write fruit;
Practical Example
Objective: Create a list of fruits and retrieve the first item.
- Create a list of fruits:
lst new fruits; lst set fruits "0" "orange"; lst set fruits "1" "grape";
- Get and display the first fruit:
lst get fruits "0" firstFruit; csl write firstFruit;
Tips
- Use clear variable and list names for better readability.
- Remember that lists are zero-indexed.
- Delete unused variables and lists to free up resources.
Conclusion
Variables and lists are the foundation for data storage and management in Virtel Steps. Use commands like var set, var get, lst new, and lst set to efficiently work with data.
Commands
Sets a value to a new variable.
value: The value to set (type: VAR).newVarName: The name of the new variable (type: VAR).
This example sets "Hello" to "greeting" and prints it to the console.
Gets the value of a variable whose name is stored in another variable and stores it in a new variable.
valueVarName: The variable containing the name of the target variable (type: VAR).newVarName: The name of the new variable to store the retrieved value (type: VAR).
This example retrieves "Hello" from "greeting" via "varName" and prints it.
Deletes a variable from the store.
newVarName: The name of the variable to delete (type: VAR).
This example deletes the "greeting" variable from the store.
Imports a variable from another flow into the current flow.
valueFlowName: The name of the flow to import from (type: VAR).varName: The name of the variable to import (type: VAR).
This example imports "sharedVar" from "flow-1" and prints its value.
Exports a variable from the current flow to another flow.
valueFlowName: The name of the flow to export to (type: VAR).varName: The name of the variable to export (type: VAR).
This example exports "sharedVar" with value "Hello" to "flow-1".
Converts a JSON string into a list and stores it in a new list variable.
varName: The variable containing the JSON string (type: VAR).newListVarName: The name of the new list variable to store the parsed list (type: LIST).
This example converts "[\"a\", \"b\"]" into a list and prints "a" from it.
Creates a new empty list.
lstName: The name of the new list (type: LIST).
This example creates an empty list "myList" and adds "item1" at index 0.
Sets a value at a specific index in a list (inserts the value at that position).
lstName: The name of the list (type: LIST).index: The index where the value will be inserted (type: VAR).value: The value to insert (type: VAR).
This example creates a list and sets "apple" at index 0 and "banana" at index 1.
Gets a value from a list at a specific index and stores it in a new variable.
lstName: The name of the list (type: LIST).index: The index of the value to retrieve (type: VAR).newVarName: The name of the new variable to store the value (type: VAR).
This example retrieves "apple" from "myList" at index 0 and prints it.
Deletes an element from a list at a specific index.
lstName: The name of the list (type: LIST).index: The index of the element to delete (type: VAR).
This example creates a list, adds "apple", and then deletes it from index 0.
Gets the length of a list (number of elements) and stores it in a new variable.
lstName: The name of the list (type: LIST).newVarName: The name of the new variable to store the length (type: VAR).
This example creates a list with one item and prints its length ("1").
Converts a list into a JSON string and stores it in a new variable.
lstName: The name of the list (type: LIST).newVarName: The name of the new variable to store the JSON string (type: VAR).
This example converts a list with "apple" into a JSON string (e.g., "[\"apple\"]") and prints it.
Imports a list from another flow into the current flow.
valueFlowName: The name of the flow to import from (type: VAR).varName: The name of the list to import (type: LIST).
This example imports "sharedList" from "flow-1" and prints its first item.
Exports a list from the current flow to another flow.
valueFlowName: The name of the flow to export to (type: VAR).varName: The name of the list to export (type: LIST).
This example exports "myList" with "apple" to "flow-1".
Creates a reference to a variable by storing its name in a new variable of type REF.
varName: The name of the variable to reference (type: VAR).newRefName: The name of the new reference variable (type: REF).
This example creates a reference to the "greeting" variable, storing it in "myRef".
Creates a reference to a variable name stored in another variable.
valueVarName: The variable containing the name of the target variable (type: VAR).newRefName: The name of the new reference variable (type: REF).
This example creates a reference to "targetVar" (stored in "varName") in "myRef".
Gets the name of the variable pointed to by a reference (not its value).
newRefName: The name of the reference variable (type: REF).
This example retrieves "greeting" from "myRef" (returns the variable name, not "Hello").
Deletes a reference from the store.
newRefName: The name of the reference to delete (type: REF).
This example deletes the reference "myRef" from the store.