For Variables
Contents
Beyond predefined variables such as functions and modules, auto-completion also supports custom-made items that you create as you script. Once you define a variable in your code, auto-completion will instantly register it as a possible option whenever searching for matches. This feature works regardless of your variable’s scope (local or global), or its location in your script (in the main function, in a user-defined module, or in a predefined module).
How It Works
As we saw in our previous example, auto-completion can help you correctly use one of Iguana’s many predefined variables (such as modules and functions). Alas, scripting goes well beyond the pre-defined! You must often create new variables in order to properly execute a task.
In this example, we have defined three simple variables:
- a string of text that we’ve named string
- a number that we’ve named number
- a table with three values that we’ve named table
In this example, we’ve also called the trace function to see our new variables in action. For more information about trace, see Using trace() to view data for debugging.
- Because auto-completion automatically adds both local and global variables to its repertoire of potential matches, anything you create in your current script is added as well. Simply start typing out the variable that you wish to use, and auto-completion will attempt to predict what you are trying to call.In this example, let’s use the trace function to return the value stored in our string variable. After choosing the trace function, we start typing the word “string” and auto-completion instantly presents us with all possible matches. Because we already defined a variable called string earlier in our script, auto-completion has already added it to the list of possibilities:
- To choose an item from an auto-completion list, click on your selection using the mouse (or scroll up and down through the list using your arrow keys). Once selected, the auto-completion tool will type out the rest of the item for you.Now let’s use trace to return the value store in our number variable:
- If your custom-made variable has several values mapped to it, auto-completion will help you drill down to the specific data that you are looking for. Similar to working with parsed message data, use auto-completion to work your way through each level of data until you find the item you seek.In this example, we want to return the second value assigned to our table variable. First, we need to choose the correct variable:
Auto-completion recognizes that table contains several fields of data, and offers us a list of options:
Let’s repeat the process to return another value from the table variable:
- Using annotations, we can see the results of our work:
Success! Thanks to auto-completion’s wide-reaching capabilities, we were able to work quickly and accurately using our own variables.