Updating and displaying a global variable ?

Discuss Lemur and share techniques.
Post Reply
amundsen
Regular
Posts: 62
Joined: 04 May 2013 19:11

Updating and displaying a global variable ?

Post 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 ?
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

Re: Updating and displaying a global variable ?

Post by Softcore »

;)
acc2.jzml
(4.15 KiB) Downloaded 171 times
amundsen
Regular
Posts: 62
Joined: 04 May 2013 19:11

Re: Updating and displaying a global variable ?

Post by amundsen »

Thanks a lot softcore ! :P
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

Re: Updating and displaying a global variable ?

Post 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 127 times
Post Reply