General
Updating and displaying a global variable ?
Started by amundsen on .
Sign in or create an account to join the conversation.
Hello,
I am trying to create a global variable, update and display it. My global variable is meant to store the lowest value encountered on the accelerometer's z axis, just to see what is the lowest value I can get when hitting the iPad's surface.
So, I have created my global variable using a project script :
However the displayed value is 0 and never changes.
What's wrong ?
I am trying to create a global variable, update and display it. My global variable is meant to store the lowest value encountered on the accelerometer's z axis, just to see what is the lowest value I can get when hitting the iPad's surface.
So, I have created my global variable using a project script :
// this script is named "mini"
// Execution: on load
decl thresh;
thresh = accelerometer[2];
Then, I have a Monitor with this script attached:// this script is named "check"
// Execution: on expression - accelerometer - any
if (accelerometer[2] < mini.thresh) {
setattribute(mini.thresh, 'value', accelerometer[2]);
}
return mini.thresh;
The value for the Monitor is set to "check()".However the displayed value is 0 and never changes.
What's wrong ?
Thanks a lot softcore ! 
No prob - BTW, your own scripts werent working because declaring an expression (variable) in a script doesnt make it "global". The expression "lives" inside the script while it is executed - when the script is ended, the expression ceases to exist. In order to have a global variable is, as you might have figured out by my example above, to use the "x=?" button and eiter define it instantly or use other scripts to define it.
In fact, my above example can be further on simplyfied (no root level act() script needed) by following the one line syntax
a?b:c conditional statement, which translates as: “if (a is true) then b else c (page 136 of Lemur manual)
Here it is!
acc2-simplified.jzml
In fact, my above example can be further on simplyfied (no root level act() script needed) by following the one line syntax
a?b:c conditional statement, which translates as: “if (a is true) then b else c (page 136 of Lemur manual)
Here it is!
acc2-simplified.jzml