Author Topic: Reaction game and timer question  (Read 3127 times)

Mikey

  • Newbie
  • *
  • Posts: 4
Reaction game and timer question
« on: October 26, 2011, 07:36:10 AM »
Hi All
Can anyone explain how to do something after a specific time has expired and how to measure a time gap?
I am making a reaction timer thats needs a random timer but cannot figure out how the time works or how to get a random number.
My tester game only has one button plus a canvas. When the player presses the button my game should display a random picture after a random time. I know how to display the picture in the canvas but don't understand the random timer part. Also after the piture has appeared how do I measure the gap between that and the canvas being touched.?
Mikey

Malkom

  • Administrator
  • Sr. Member
  • *****
  • Posts: 287
Re: Reaction game and timer question
« Reply #1 on: October 26, 2011, 08:52:45 PM »
Hi Mikey

Hi All
Can anyone explain how to do something after a specific time has expired and how to measure a time gap?
Timers are a good way to do an operation after a certain time period has elapsed. They can also be set to repeat the operation continuously.
HAC has two types of timers - the Main Timer and Card Timers. The Main Timer can operate even when cards (screens) are changed. Card Timers are controls that can be placed on a card, are invisible, and are only active on that card. Card Timers can be found on the controls section of the toolbar.

Assuming a card timer use this command to make it fire after 2.5 seconds. Place it in your button.

Code: [Select]
TimerSet(1,1,2500)
Where:
the first parameter is the timer number,
the second parameter is its mode 0 = off, 1 = fire once, 2 = fire repeatedly
the third parameter is the delay in milliseconds.



I am making a reaction timer thats needs a random timer but cannot figure out how the time works or how to get a random number.

The RndFN function returns an integer value between and including the two parameters:-

Code: [Select]
@ set random time to between 3 to 5 seconds
Put RndFN(3000,5000) into delay
TimerSet(1,1,delay)



My tester game only has one button plus a canvas. When the player presses the button my game should display a random picture after a random time. I know how to display the picture in the canvas but don't understand the random timer part. Also after the piture has appeared how do I measure the gap between that and the canvas being touched.?
Mikey

Elapsed time can be measured using either the TicksFN or MicroSecondsFN functions. TicksFN measures 60th seconds. Note, MicrosSecondsFN is only accurate to milliseconds on an Android device.

In your timer put this code:-

Code: [Select]
Global startTime

Put  MicrosSecondsFN into startTime



In your canvas event put this code:-

Code: [Select]
Global startTime
Local nowTime

Put  MicrosSecondsFN into nowTime
Subtract startTime from nowTime


Malkom


I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.

Mikey

  • Newbie
  • *
  • Posts: 4
Re: Reaction game and timer question
« Reply #2 on: October 27, 2011, 04:40:06 PM »
Thank you Malkom, just what I was looking for :)