Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Previous section Next section Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Topic:
Page script question
This thread has 2 replies. Displaying all posts.
Post 1 made on Wednesday October 21, 2020 at 09:31
Fischi
Long Time Member
Joined:
Posts:
January 2011
114
H,
I have a question:
In the page properties we have 1) Execute once when page is shown
and
2) Repeat every ... seconds.

1) is clear for me.

2) is not clear for me:

will the page script be repeated only when the page is opened (shown)
or will it be repeated every ... seconds in the background, also if I'm on other pages/activities (I mean when another page is shown) ?

Regards,
Fischi
Post 2 made on Wednesday October 21, 2020 at 16:22
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,985
By default, when you leave a page or an activity, any script that is running on them will be cleared. The page script will be executed upon entry to a page and then again after the repeat interval (milliseconds). Therefore, I would strongly recommend defining variables that your page needs at the activity level.

Also, I would recommend you see the Page.onEntry and Page.onExit documentation in the Dev Guide.

Let's try a little experiment.

Create a new activity.

In the Activity script, define a variable named counter and a function to display and increment.


var counter=0;

function displayAndIncrement() {
var w = GUI.widget('MyCounterValue');
if (w) {
w.label = '' + counter;
}
counter +=1;
}


On a page in same Activity, create a label widget with the ProntoScript name of 'MyCounterValue'.

Then, in the Advanced Tab of same page, set script to non repeat. In the script area, have it call the function you defined earlier.


displayAndIncrement();


When you simulate the config, you should see a value of '0' displayed in your widget.

Next, on the same page, add a button. In the Buttons' Prontoscript, have it call the same function.


displayAndIncrement();


Now, every time you press the button, you should see the counter go up.


Finally, change your page script to repeat ever 1 second.

When you run/simulate the config, the counter value in the widget will increase by 1 every 1 second.

Now, add a 2nd page to the activity such that you can Page Up/Down between the pages.

Now page up/down between the pages. You should see that the counter value is maintained because it is defined at the Activity level and not at the Page level.

To illustrate why we put the function and counter variable in the Activity vs in the Page, simply copy the variable declaration and the function to your page that has the repeat interval set such that the script looks like this.


// BEGIN copied from Activity
var counter=0;

function displayAndIncrement() {
var w = GUI.widget('MyCounterValue');
if (w) {
w.label = '' + counter;
}
counter +=1;
}
// END copied from Activity

// Now, call the function.
displayAndIncrement();


What you should now see is that if you press that Button you created, the counter will incremement but as soon as the page script executes again, the value resets to 0.

This whole exercise illustrates the scope chain in Javascript and how variable/function lookups apply.

Global
PS Library
Activity
Page
Button

Finally, on that page you just moved stuff into (the one with the repeat interval), comment out the variable declaration line (NOTE - This will only work if you still have the variable declared at Activity Level meaning that you copied and did not remove the script in the Activity).


// BEGIN copied from Activity
//var counter=0;

function displayAndIncrement() {
var w = GUI.widget('MyCounterValue');
if (w) {
w.label = '' + counter;
}
counter +=1;
}
// END copied from Activity
displayAndIncrement();


Simulate and you should see the counter increment every 1 second or so (depending on the Page Repeat Interval).

Also note that I am using GUI.widget vs CF.widget to lookup the widget. This is because Activity script can execute before a page is loaded and ready to be displayed. At one point and time, I posted a thread about the differences between CF.widget and GUI.widget.

[Link: remotecentral.com]

You will want to see the last post of the first link in the above thread.

[Link: remotecentral.com]

Lyndel
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 3 made on Wednesday October 21, 2020 at 16:32
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,985
Just to be explicitly clear....

If you navigate away from a Page that has a Repeat Interval, that page will cease to execute. Furthermore, any variables declared on that page will no longer exist.
Lyndel McGee
Philips Pronto Addict/Beta Tester


Jump to


Protected Feature Before you can reply to a message...
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now.

Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.

Hosting Services by ipHouse