contents   index   previous   next



EXAMINING VARIABLES

 

Now that you know how to select the variable you are interested in, let's look at examining its value. JavaScript does not have variables of fixed type. When a script is run, any variable can be assigned a value of any type. Each can be assigned values of differing types as the script continues. For this reason, you have to look to see what type a variable currently is. You do this using the seGetType API call. This tells you what type an object member is. You can use this information to execute different code based on the type of a variable.

 

Fortunately, you can let ScriptEase worry about converting types and just ask to get a variable's value as a certain type. If the variable is not of the correct type, it is converted. This is useful because many JavaScript functions are designed to work this way; when passing parameters to the standard JavaScript functions, they are converted to the type the function expects automatically. If you allow ScriptEase to do the same when you are accessing variables, you will automatically follow the JavaScript standard that variables are converted to the correct type whenever necessary. The seGetXXX functions, where XXX is based on the type you'd like to get, convert the ScriptEase variable value to the given type and return it to you, in C format. Note that the variable is not permanently changed. You can use the seConvertXXX API call to do that.

 

All of the API calls that read a variable's value, either to get its type or get its value, read the value exactly once per API call. This is important to understand the behavior of dynamic objects. If you just use seGetXXX, the value is read, converted to the required type, and returned to you. This is the preferred method. However, you may want to read the type then get the value of that particular type, presumably to do different things based on the variable's type. Understand that this involves two calls to API functions that read the value, one to seGetType and one to a seGetXXX. This means the value will be read twice. If the object the member is being retrieved from is dynamic, that dynamic get will be called twice. It is possible for it to return two different values, defeating the purpose of your code.

 

In this situation, because seGetXXX is safe, your code will not crash just operate unexpectedly. You can ignore such objects and let the object's designer worry about it. Alternately, you can use seAssign to grab the value and store it in a temporary location. This will read the value once. Now you can use seGetType and seGetXXX on that stored value, knowing it will not change.

 


MODIFYING VARIABLES