PDA

View Full Version : TIMER advice



catventure
12-12-2005, 21:01
Hi,

Need some advice here...
I want to add a 'timeout' feature to my text adventure project.
If the player takes too long to type in some text input into a textbox control - and press a button control to 'enter' it, then I wish to cause a message such as "Time Passes..." to appear in the output textbox.

I've assumed I may need to do something along the lines of below using TIMER:

dim tempval as double
dim timeout as long value 30

'set 30 second timeout??
tempval=TIMER+timeout

and then immediately after that some sort of loop to check whether the 30 seconds has passed:

if TIMER>=tempval then
control append text hdlg,%ID_TEXTBOX1,"Time Passes..."
end if

The timeout would need to be aborted should the player respond within the 30 seconds and reset after text output for the next player input...

I'm not quite sure how to code it and whether or not the check should be in the dialog window event handler loop or outside of it...

I tried a few things but not having much joy.

Regards,
catventure.

ErosOlmi
13-12-2005, 16:05
Hi catventure.

Using you game ...
add 2 variables at the beginning:

dim TimeBase as double
dim TimeElap as double

and add the following code at around line 870. It should work.
In future I'm pretty sure I will be able to allow to add timers inside scripts. Not now, sorry.

Let me know
Eros

'---Init base timer
TimeBase = timer

'---Track Windows Events
WHILE IsWindow(hwnd)

'---Get the message and fill wParam and lParam
Msg = GetMessage(hwnd, wParam, lParam)

'---Init ongoing timer and check difference if > 10 seconds
'---If yes, emit a message
TimeElap = timer
if TimeElap - TimeBase > 10 then
control append text hwnd,%id_RICHEDIT2,crlf+"... are you there?..."
TimeBase = timer
end if
'---Now test the message
SELECT CASE Msg

case %WM_INITDIALOG '---Message fired at the very beginning when dialog is initialized
'---Attach menu to dialog
MENU ATTACH hMenu, hwnd

CASE %WM_COMMAND
select case wparam
'Alternative try to get player input with <return> press
Case %MY_SECRET_BUTTON
'---If player hits <RETURN> get their inputted text and clear input textbox
' IF GetAsyncKeyState(%VK_RETURN) <> 0 then
control get text hwnd,%ID_TEXTBOX2 TO tempstr
'control set text hwnd,%ID_RICHEDIT,""
control set text hwnd,%ID_TEXTBOX2,""
'control set text hwnd,%ID_RICHEDIT," You typed: " & tempstr
translateuserinput

'---In case user input reset base timer
TimeBase = timer
end select

catventure
13-12-2005, 18:34
Hi Eros,

Welcome Back. Hope your holiday was good.

Yes, that worked just fine.

I knew there must be a way but couldn't figure it...

Thank you for that. I've put that in to my code and worked well!

I also updated my adventure project with latest additions here:

http://www.staining.fslife.co.uk/tbasic.htm

Still a way to go but its good fun making it! :)

Regards,

catventure.