PDA

View Full Version : Creating a "Timer" function?



CPG33
12-28-2005, 08:48 AM
I'm creating a kiosk application and want to add a "Time Out" function. Essentially, if nothing has been done (clicked on) for 5 minutes - I want the application to go to a specific page that will play a looped video until a user clicks on something.

Here's my logic:
- When the application launches, start a time counter; although I'm not sure if this should be a "Global Function" or an "On Startup" event??
- Apply an "on-click" action to every button in the application that resets the counter to zero
- If the counter reaches 5 minutes (or ?? value), then go to page X

I guess that what I'm looking for is guidance on what type of action or scripts I should be using? Has anyone built anything like this before?

Thanks in advance for any help!

TJ_Tigger
12-28-2005, 10:01 AM
Try the following code. Put this in your On Timer event for each page of your project. This code will create a couple of variable to track when ever the "On Click" event fires for a button. With the way the code works, you shouldn't have to add any additional script to your buttons as the initialization section will do that for you. I have not tested the code on a multipage project so I don't know what will happen but the code may need to be adjusted to work in a multipage project. Adding a variable to the page that resets the LastEvent == nil should do the trick. Here it is



if LastEvent then --check to see if the variable has been initialized
if EventCheck ~= LastEvent then --Someone has clicked an object and caused an event
--reset the counter
nTimeout = 0;
LastEvent = EventCheck
else
nTimeout = nTimeout + 1;
--uncomment the following line to have an object on the page show the counter incrementing
--Label.SetText("Label1", EventCheck.."-"..nTimeout);
if nTimeout >= 420 then -- this number assumes a one second timer and will timeout after 5 mins.
Page.Jump("Page2") -- jump to the page after the timeout.
end
end
else
--initialize values
EventCheck = Debug.GetEventContext();
LastEvent = EventCheck;
nTimeout = 0;
--initialize all button objects to contain the debug action on their On Click event
tbObjects = Page.EnumerateObjects();
for i,v in tbObjects do
if Page.GetObjectType(v) == OBJECT_BUTTON then
PreviousScript = Page.GetObjectScript(v, "On Click");
if String.Find(PreviousScript, "EventCheck = Debug.GetEventContext();", 1, true) == -1 then
Page.SetObjectScript(v, "On Click", PreviousScript.."\r\nEventCheck = Debug.GetEventContext();");
end
end
end
end

Worm
12-28-2005, 10:04 AM
Cool idea Tig!!

TJ_Tigger
12-28-2005, 10:10 AM
Thanks Worm, I think it has potential. As I keep playing with it there are lots of things that I could keep adding to make it more robust.

If I come up with a better one I will post the code again.

Tigg

TJ_Tigger
12-28-2005, 10:23 AM
Here is some more code using a function to add code onto an object.

Global Function


function EditScript(strObject, strEvent, strCode2Add)
local PreviousScript = Page.GetObjectScript(strObject, strEvent);
if String.Find(PreviousScript, strCode2Add, 1, true) == -1 then
Page.SetObjectScript(strObject, strEvent, PreviousScript.."\r\n"..strCode2Add);
end
end


On Timer function


if LastEvent then --check to see if the variable has been initialized
if EventCheck ~= LastEvent then --Someone has clicked an object and caused an event
--reset the counter
nTimeout = 0;
LastEvent = EventCheck
else
nTimeout = nTimeout + 1;
--uncomment this line to have an object on the page show the counter incrementing
--Label.SetText("Label1", EventCheck.."-"..nTimeout);
if nTimeout >= 420 then -- this number assumes a one second timer and will timeout after 5 mins.
Page.Jump("Page2") -- jump to the page after the timeout.
end
end
else
--initialize values
EventCheck = Debug.GetEventContext();
LastEvent = EventCheck;
nTimeout = 0;
--initialize all button objects to contain the debug action on their On Click event
tbObjects = Page.EnumerateObjects();
for i,v in tbObjects do
--additional objects and events could be placed here to allow their events to be tracked and reset the timer.
if Page.GetObjectType(v) == OBJECT_BUTTON then
EditScript(v, "On Click", "EventCheck = Debug.GetEventContext();")
elseif Page.GetObjectType(v) == OBJECT_LISTBOX then
EditScript(v, "On Double-Click", "EventCheck = Debug.GetEventContext();")
EditScript(v, "On Select", "EventCheck = Debug.GetEventContext();")
end
end
end


One may want to add a timestamp into the event detection as well especially if you are using listboxes or other items to view content within your project. The code above will not reset the timer if you only click in a single listbox.

Worm
12-28-2005, 10:33 AM
Still, way cool!

I'd not thought about using that action to add code to an existing object. I've only been using it to add to new objects.

Definitely outside the rectangular object thinking fer sure :yes

TJ_Tigger
12-28-2005, 10:51 AM
Thanks Worm :D Everyone knows that T-Eye-Dubble-Guh-Rrrrrrs are never thquare.

here is the code for buttons and listboxes and a timestamp for each event. You know that this code could easily be added to objects for creating a log for what happens in the project.



if LastEvent then --check to see if the variable has been initialized
if EventCheck ~= LastEvent then --Someone has clicked an object and caused an event
--reset the counter
nTimeout = 0;
LastEvent = EventCheck
else
nTimeout = nTimeout + 1;
--uncomment this line to have an object on the page show the counter incrementing
--Label.SetText("Label1", EventCheck.."-"..nTimeout);
if nTimeout >= 420 then -- this number assumes a one second timer and will timeout after 5 mins.
Page.Jump("Page2") -- jump to the page after the timeout.
end
end
else
--initialize values
EventCheck = Debug.GetEventContext();
LastEvent = EventCheck;
nTimeout = 0;
--initialize all button objects to contain the debug action on their On Click event
tbObjects = Page.EnumerateObjects();
for i,v in tbObjects do
AddInScript = "EventCheck = System.GetDate(DATE_FMT_JULIAN)..\".\"..((System.GetTime(TIME_FMT_HOUR) * 3600)+(System.GetTime(TIME_FMT_MIN) * 60)+System.GetTime(TIME_FMT_SEC))..\" \"..Debug.GetEventContext();";
--additional objects and events could be placed here to allow their events to be tracked and reset the timer.
if Page.GetObjectType(v) == OBJECT_BUTTON then
EditScript(v, "On Click", AddInScript)
elseif Page.GetObjectType(v) == OBJECT_LISTBOX then
EditScript(v, "On Double-Click", AddInScript)
EditScript(v, "On Select", AddInScript)
end
end
end

CPG33
12-28-2005, 12:07 PM
Sincere thanks for the idea (far more simple and elegant than what I was thinking) and code to make it happen! I'll do my best not to fumble the hand-off! ;)

Kindest regards,
Gary D.

Intrigued
12-28-2005, 05:14 PM
TGI'TIGG day!

:D

Corey
12-28-2005, 05:28 PM
Tiggnificent. :yes

yosik
12-29-2005, 12:01 PM
Transcending
Irregular
Great

That's Tig...And eleGant too...

Yossi