Reaction Time Task
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Reaction Time Task
Hi all,
I am trying to code a basic reaction time task where the fixation cross "+" appears for a varying amount of time and then "GO" is presented. I have created a variable called Times with 200, 400, 600, and 800 in it. I want the fixation cross to display for each of these varying times. I've tried some if then loops and repeats but nothing is happening. I am very new to livecode and know this problem is probably fairly easy to the LC experts.
My current code for the button that begins the experiment is below. The repeat 8 times doesn't work but the randomization does. Another problem is I don't know how to make an item in a list be read as a time.
This is my code:
on mouseUp
go to card 3
put empty into field StimTimes
hide field StimTimes of card 3
hide field Data of card 3
repeat 8 times
put "200, 400, 600, 800" into Times
sort items of Times by random(800)
put Times into field StimTimes
end repeat
put "+" into field StimPres
wait items of Times in milliseconds
put "GO" into field StimPres
end mouseUp
Thank you for your help!!
I am trying to code a basic reaction time task where the fixation cross "+" appears for a varying amount of time and then "GO" is presented. I have created a variable called Times with 200, 400, 600, and 800 in it. I want the fixation cross to display for each of these varying times. I've tried some if then loops and repeats but nothing is happening. I am very new to livecode and know this problem is probably fairly easy to the LC experts.
My current code for the button that begins the experiment is below. The repeat 8 times doesn't work but the randomization does. Another problem is I don't know how to make an item in a list be read as a time.
This is my code:
on mouseUp
go to card 3
put empty into field StimTimes
hide field StimTimes of card 3
hide field Data of card 3
repeat 8 times
put "200, 400, 600, 800" into Times
sort items of Times by random(800)
put Times into field StimTimes
end repeat
put "+" into field StimPres
wait items of Times in milliseconds
put "GO" into field StimPres
end mouseUp
Thank you for your help!!
-
- VIP Livecode Opensource Backer
- Posts: 9646
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Reaction Time Task
Sounds like fun, though I am not sure exactly what you want. But no matter. We will suggest stuff, you will test and practice, back and forth, until you are adept. In the meantime, on a new card make a field and a button. Lock the field and place this into its script:
in the button script:
The values are arbitrary. If you click on the button, you have a short time to click on the field to win.
Now there are a lot of things here that can be tightened, and much that can be embellished. And I use global variables because they are easy to understand. Otherwise I never use them, but that is for later. Oh, and there are better ways than using "wait" of any kind.
Write back with your comments. And start working on making this what you likely really wanted in the first place.
Craig Newman
Code: Select all
global tTicks
on mouseup
if the ticks - tTicks < 70 then
hide fld 1
answer "Bingo!"
exit to top
end if
end mouseup
Code: Select all
global tTicks
on mouseUp
show fld 1
put the ticks into tTicks
wait random(50) + 50 with messages
if the visible of fld 1 then
hide fld 1
answer "Too Bad"
end if
end mouseUp
Now there are a lot of things here that can be tightened, and much that can be embellished. And I use global variables because they are easy to understand. Otherwise I never use them, but that is for later. Oh, and there are better ways than using "wait" of any kind.
Write back with your comments. And start working on making this what you likely really wanted in the first place.
Craig Newman
Re: Reaction Time Task
Thank you Craig!
I have added to your code to make it more of a reaction time task but I have run into some problems. In the field, a "+" shows for a random time and then GO is presented. I then tried to have the time after "GO" is presented and a tick be put into an added field called data, this would be the reaction time. This only works if the tick happens while the "+" is present. I also tried hiding the field data but that doesn't work either. I had the same problem when trying to show and hide fld 1 in your original code. I didn't delete much of your original code but instead added to it, as I was afraid of messing up the entire thing.
My code for the field is:
global tTicks
on mouseup
hide field data
if the ticks - tTicks <70 then
put the milliseconds into field data
answer "Bingo!"
exit to top
end if
end mouseup
and my code for the button is:
global tTicks
on mouseUp
put the ticks into tTicks
put "+" into fld 1
wait random(50) + 50 with messages
put "GO" into fld 1
if the visible of fld 1 then
hide fld 1
answer "Too Bad"
end if
end mouseUp
I am continuing to tweek it to become more of the reaction time task I want.
Thank you for your help!
Marissa
I have added to your code to make it more of a reaction time task but I have run into some problems. In the field, a "+" shows for a random time and then GO is presented. I then tried to have the time after "GO" is presented and a tick be put into an added field called data, this would be the reaction time. This only works if the tick happens while the "+" is present. I also tried hiding the field data but that doesn't work either. I had the same problem when trying to show and hide fld 1 in your original code. I didn't delete much of your original code but instead added to it, as I was afraid of messing up the entire thing.
My code for the field is:
global tTicks
on mouseup
hide field data
if the ticks - tTicks <70 then
put the milliseconds into field data
answer "Bingo!"
exit to top
end if
end mouseup
and my code for the button is:
global tTicks
on mouseUp
put the ticks into tTicks
put "+" into fld 1
wait random(50) + 50 with messages
put "GO" into fld 1
if the visible of fld 1 then
hide fld 1
answer "Too Bad"
end if
end mouseUp
I am continuing to tweek it to become more of the reaction time task I want.
Thank you for your help!
Marissa
Re: Reaction Time Task
Hi Marissa,
1. welcome to the forum!
2. Still not sure what exactly you want to do, but here an important hint:
Always put strings, like names of objects etc., in QUOTES!
Here I used your "wait" times as mentioned in your first script.
Please look up any unknown term in the dictionary
Best
Klaus
P.S.
Here some great learning resources for the basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html
1. welcome to the forum!
2. Still not sure what exactly you want to do, but here an important hint:
Always put strings, like names of objects etc., in QUOTES!
Code: Select all
global tTicks
on mouseup
hide field data
if the ticks - tTicks <70 then
put the milliseconds into field "data"
answer "Bingo!"
## Since this is the end of this script, the next line is not neccessary
## exit to top
end if
end mouseup
Please look up any unknown term in the dictionary
Code: Select all
global tTicks
on mouseUp
put the ticks into tTicks
put "+" into fld 1
put ANY item of "200,400,600,800" into tWait
wait tWait millisecs with messages
put "GO" into fld 1
if the visible of fld 1 then
hide fld 1
answer "Too Bad"
end if
end mouseUp
Klaus
P.S.
Here some great learning resources for the basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html
Re: Reaction Time Task
Thank you Klaus! I apologize for being vague on what I am trying to accomplish. I am trying to make a reaction time task, it is often used for psychology research. The main idea to is measure the time is takes a person respond, by pressing a key, after being presented a stimulus or in this case, a GO message. So the person sees a "+" for a varying amount of time and then a GO signal. Once they see the GO, they are to press a specified key. The time in between the presentation of the GO and their key press is their reaction time. I want to vary the time the "+" is presented so the person is not getting into a fixed rhythm when responding because that would probably mess up the data.
I have implemented the part of your code that puts the times I mentioned above into tWait. An error pops up that says the handler cant be found. Could that be because the code is in the button and not the card? I created a global variable for tWait but that didnt solve the issue.
I am attaching my code below with some changes.
Thanks again for your help and the link to learning resources!
Marissa
I have implemented the part of your code that puts the times I mentioned above into tWait. An error pops up that says the handler cant be found. Could that be because the code is in the button and not the card? I created a global variable for tWait but that didnt solve the issue.
I am attaching my code below with some changes.
Code: Select all
global tTicks
global tWait
on mouseUp
put the ticks into tTicks
put "+" into fld 1
put ANY item of "200, 400, 600, 800" in tWait
wait tWait milliseconds with messages
put "GO" into fld 1
end mouseUp
Code: Select all
global tTicks
put empty into field data
on keydown whichkey
global toggleResponse -- to account for multiple key presses error
put the milliseconds into RT
if toggleResponse is 1 then
put 0 into toggleResponse
put RT & tab & tWait & whichkey & return after field data
end if
end keydown
hide field data
Marissa
Re: Reaction Time Task
Hi Marissa,
oh sorry, I had a typo in my script, of course it has to read:
...
put ANY item of "200, 400, 600, 800" INTO tWait
## So no need for another global variable.
...
Your other script is not correct:
Best
Klaus
oh sorry, I had a typo in my script, of course it has to read:
...
put ANY item of "200, 400, 600, 800" INTO tWait
## So no need for another global variable.
...
Your other script is not correct:
Code: Select all
global tTicks
## This line needs to be inside of a handler (mouseup, keydown or wherever this makes sense, it will not be executd in this place!
## And the QUOTES thing, if I did not mention this already :D
'## put empty into field "data"
on keydown whichkey
global toggleResponse -- to account for multiple key presses error
put the milliseconds into RT
if toggleResponse is 1 then
put 0 into toggleResponse
put RT & tab & tWait & whichkey & return after field data
end if
end keydown
## Same for this line!
# hide field "data"
Klaus
Re: Reaction Time Task
Thank you Klaus for your help.