Page 1 of 1

Updating and displaying a global variable ?

Posted: 04 May 2013 23:40
by amundsen
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 :

Code: Select all

// this script is named "mini"
// Execution: on load
decl thresh;
thresh = accelerometer[2];
Then, I have a Monitor with this script attached:

Code: Select all

// 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 ?

Re: Updating and displaying a global variable ?

Posted: 05 May 2013 14:39
by Softcore
;)
acc2.jzml
(4.15 KiB) Downloaded 170 times

Re: Updating and displaying a global variable ?

Posted: 05 May 2013 17:42
by amundsen
Thanks a lot softcore ! :P

Re: Updating and displaying a global variable ?

Posted: 06 May 2013 09:37
by 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
(3.97 KiB) Downloaded 126 times