Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 11 of 11
  1. #1
    Join Date
    Jun 2002
    Posts
    6

    Creating a "Timer" function?

    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!

  2. #2
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    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

    Code:
    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
    Last edited by TJ_Tigger; 12-28-2005 at 09:09 AM.
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  3. #3
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    Cool idea Tig!!

  4. #4
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    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
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  5. #5
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    Here is some more code using a function to add code onto an object.

    Global Function
    Code:
    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
    Code:
    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.
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  6. #6
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    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

  7. #7
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    Thanks Worm 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.

    Code:
    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
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  8. #8
    Join Date
    Jun 2002
    Posts
    6

    Thanks

    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.

  9. #9
    Join Date
    Dec 2003
    Location
    Location! Location!
    Posts
    6,137
    TGI'TIGG day!

    Intrigued

  10. #10
    Corey is offline Indigo Rose Staff Alumni
    Join Date
    Aug 2002
    Posts
    9,746
    Tiggnificent.

  11. #11
    Join Date
    Jun 2002
    Location
    Israel
    Posts
    1,843
    Transcending
    Irregular
    Great

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

    Yossi

Similar Threads

  1. Function: FindAndCloseProcessByName
    By Brett in forum Setup Factory 8.0 Examples
    Replies: 14
    Last Post: 01-19-2011, 07:08 AM
  2. Another tough one... Interaction between Web and AMS
    By Agent Jones in forum AutoPlay Media Studio 5.0
    Replies: 13
    Last Post: 08-18-2005, 02:10 PM
  3. Function: String.RandomFromPattern
    By Brett in forum Setup Factory 8.0 Examples
    Replies: 0
    Last Post: 10-28-2004, 08:09 AM
  4. Bizarre Callback Function Behaviour - Can anyone help?
    By SRJ in forum AutoPlay Media Studio 5.0
    Replies: 3
    Last Post: 06-30-2004, 09:16 PM
  5. Function: Resize & Center an Image
    By kpsmith in forum AutoPlay Media Studio 5.0 Examples
    Replies: 0
    Last Post: 05-17-2004, 01:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts