forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Brain Reflex Test

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Miscellaneous
View previous topic :: View next topic  
Author Message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Sun May 10, 2009 3:23 pm    Post subject: Brain Reflex Test Reply with quote

Simple brain reflex game where you need to click the square as soon as possible after it changes color.
The square changes to a random color anywhere from 3 to 8 seconds after you click the Start button.
Code:

  REM Initialize %%time
  %%time = None

  Title Brain Reflex Test
  DIALOG CREATE,Brain Reflex Test,-1,0,356,290
  DIALOG ADD,STYLE,STYLE1,,,BC,,
  DIALOG ADD,SHAPE,SHAPE1,75,85,180,180,WHITE,BLACK,,SQUARE,CLICK
  DIALOG ADD,BUTTON,Start,257,85,180,30,Start
  DIALOG ADD,TEXT,TEXT1,5,40,265,65,,,STYLE1
  DIALOG SHOW
 
  REM Kernel32 contains the GetTickCount Function
  loadlib kernel32.dll
 
  REM List of colors
  list create,1
  list add,1,255|0|0
  list add,1,255|0|255
  list add,1,128|0|0
  list add,1,0|255|0
  list add,1,255|255|0
  list add,1,0|128|0
  list add,1,0|0|255
  list add,1,0|255|255
  list add,1,0|0|128
 
  REM Seed the @random function
  RANDOM @datetime(ddmmnnss)
 
  REM Set TEXT1
  gosub SetText
:Evloop
  wait event
  goto @event()
:SHAPE1CLICK
  REM Make sure user has clicked start by checking Timer 2's Status
  REM 1 = Running
  if @equal(@timer(2,S),1)
    REM Use GetTickCount to subtract the current tick count from %%start
    %%end = @lib(kernel32,GetTickCount,INT:,VOID:)
    REM Find milliseconds that it took to click the square
    %%time = @fsub(%%end,%%start)
    REM Divide %%time by 1000 to find seconds and format it
    %%time = @format(@fdiv(%%time,1000),2.3)
    REM Stop Timer 2, its not needed anymore
    timer stop,2
    REM Show the time taken
    gosub SetText
    REM Set the square back to white and start button to Start
    dialog set,shape1,255|255|255
    dialog set,Start,Start
  end
  goto evloop
:StartBUTTON
  REM Check if user has already clicked start
  if @equal(@timer(1,S),1)
    REM Reset timers, square, and start button
    timer stop,1
    timer stop,2
    dialog set,shape1,255|255|255
    dialog set,Start,Start
  else
    dialog set,start,Stop
    REM Set a countdown timer with a random amount of seconds between 3 and 10
    REM When the timer counts down we will change the square color
    timer start,1,ctdown,00-00:00:@random(3,8) 
  end
  goto evloop
:Timer1CTDOWN
  REM Timer 1 has counted down set the square to a random color from list 1
  dialog set,shape1,@item(1,@random(0,8))
  REM Use GetTickCount to determine how long before the user clicked later
  %%start = @lib(kernel32,GetTickCount,INT:,VOID:)
  REM Start timer number 2, the chrono timer
  REM If this timer counts down, it has been 10 seconds
  REM We will stop this timer if the user clicks the square
  timer start,2,chrono,00-00:00:10
  goto evloop
:Timer2CHRONO
  REM Set the square back to white and start button to Start
  dialog set,shape1,255|255|255
  dialog set,Start,Start
  REM Tell the user they took too long
  %%time = 0.0
  gosub SetText
  goto evloop
:SetText
  REM Set end message based on user's time
  %%msg = You Took Too Long!
  if @both(@greater(%%time,0.25),@not(@greater(%%time,0.35)))
    %%msg = Good!
  end
  if @both(@greater(%%time,0.25),@not(@greater(%%time,0.45)))
    %%msg = Keep Practicing!
  end
  if @both(@greater(%%time,0.25),@greater(%%time,0.45))
    %%msg = You Need Practice!
  end
  if @both(@greater(%%time,0.0),@not(@greater(%%time,0.25)))
    %%msg = Excellent!
  end
  if @equal(%%time,None)
    %%msg = ""
  end
 
  dialog set,text1,Click the Start button and then get ready to click the Big Square when it changes color.@cr()Try to beat 0.25.@cr()@cr()Last time: %%time %%msg
  exit
:Close
  exit

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Sun May 10, 2009 5:05 pm    Post subject: Reply with quote

What version of VDS? I'm using 6 and get the following error when I tried it:

Code:
Error:  Missing parameter(s) to command
at line: 66


which is this line of code here:

Code:
timer start,1,ctdown,00-00:00:@random(3,8)

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Back to top
View user's profile Send private message
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Sun May 10, 2009 5:08 pm    Post subject: Reply with quote

I looked at that line longer, cross ref'd against the help file, and I see nothing wrong myself. Sad
_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Back to top
View user's profile Send private message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Sun May 10, 2009 5:57 pm    Post subject: Reply with quote

Wow, must be VDS 6.. wonder what would have been changed in the timer code between 5 and 6Question
Can't be the @random function can it?

You could try changing it to chrono instead of ctdown and make sure to change :Timer1CTDOWN to :Timer1CHRONO

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
Hooligan
VDS Developer
VDS Developer


Joined: 28 Oct 2003
Posts: 480
Location: California

PostPosted: Mon May 11, 2009 12:49 pm    Post subject: Reply with quote

Actually, the timer in VDS6 uses a floating point number instead of a formatted string... Change line 66 to:

Code:
timer start,1,ctdown,@fdiv(@random(3,8),86400)


and line 77 to:

Code:
timer start,2,chrono,@fdiv(10,86400)


Hooligan

_________________
Hooligan

Why be normal?
Back to top
View user's profile Send private message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Mon May 11, 2009 1:13 pm    Post subject: Reply with quote

Excellent backwards compatibility.. Rolling Eyes
_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Miscellaneous All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group