State variables are named memory locations with a specified data type which may have associated state transitions.
Note: If you are new to variables, see Variables Explained.
A state variable is a named area of device memory containing a value of a specified type, almost exactly like a regular variable. See Variables. The main difference is that a state variable may have one or more associated state transitions. See State Transitions.
In UJML, a state variable is declared using a state-var element inside of a state-variables element. See state-var, state-variables. A state variable must have a valid name and data type. See Identifiers, Data Types. Variable scope is determined by the element containing the state-variables element in which the state-var is declared. See Data Scoping and Sharing.
Note: All UJML data types are valid for a state variable except reference. See reference data type.
A state variable may be assigned the value of another variable, a literal, a function call result, or an expression of the proper data type. Until the state variable is assigned an initial value, it has a default value assigned when the state variable was created.
|
Data Type |
Default Value |
|
boolean |
false |
|
int |
0 |
|
string |
"" (Empty string) |
A state variable may be defined as an array using the size attribute of the state-var element. See Arrays. Any one array element acts exactly like a simple state variable of the same data type. Array state variables may not be assigned to or passed as function arguments without specifying an array element.
A state variable exists in memory for the lifetime of the application.
A state variable may not be declared inside of a function element. See User Defined Functions. You may pass the value of a state variable to a function, as a parameter, exactly like a regular variable. See Using Functions.
The following example shows how to declare two boolean state-variables. It is part of the helloworld4.ujml sample.
<state-variables>
<state-var name="sHelloBox" type="boolean"/>
<state-var name="sInput" type="boolean" />
</state-variables>
The following example shows how to set the state-variables declared above to a boolean literal to start the application. It is part of the helloworld4.ujml sample.
sHelloBox = true; sInput = true;
The following example shows how to handle an onSelect event for the left-arrow button by updating a position variable and resetting the sHelloBox state variable using the _clear_state() function to move the visual elements displayed by the transition element. It is part of the helloworld4.ujml sample.
<event name="onSelect">
<accelerators>
<key>LEFT</key>
</accelerators>
<script>
mPosX = mPosX - &MOVEMENT;;
if (mPosX &_LT; 0)
{
mPosX = 0;
}
_clear_state(sHelloBox);
sHelloBox = true;
</script>
</event>
The following example shows how to handle a state transition for the 'sHelloBox' state-variable by displaying a round-box containing a label. It is part of the helloworld4.ujml sample.
<state var="sHelloBox">
<transition value="true">
<display>
<!-- Say Hello on the screen using a label inside of a box. -->
<round-box>
<x><eval>mPosX</eval></x>
<y><eval>mPosY</eval></y>
<width>
<eval>mWidth</eval>
</width>
<height>
<eval>mHeight</eval>
</height>
<fg>&_COLOR_GRAY;</fg>
<bg>&_COLOR_PURPLE;</bg>
<x-arc-width>8</x-arc-width>
<label>
<text>&SALUTATION;</text>
<x>&SPACING;</x>
<y>&SPACING;</y>
<fg>&_COLOR_WHITE;</fg>
<size>&_FONT_SIZE_LARGE;</size>
<style>&_FONT_STYLE_ITALIC;</style>
<face>&_FONT_FACE_SYSTEM;</face>
</label>
</round-box>
</display>
</transition>
</state>|
Copyright (c) 2000-2007 UIEvolution, Inc. All rights reserved.
|
|
What do you think about this topic? Send feedback!
|