Ye1993
April 17, 2020, 5:29pm
1
Exp background
#mouse-click #picture
Participants’ task: use mouse to click 1 out of 4 pictures;
Exp’s task:
a. compare the selected picture with the target in the condition file;
b. generate a “score” column
–correct coded as 1,
–incorrect coded as 0.
Offline–able to get “score” if being run in Builder
The line works:
“thisExp.addData(‘score’, int(correctAcc == imageTest1))”
int(target pic in condition file == pic shown)
Able to get the “score”:
Online–Unable to get “score” if being run in Pavlovia
The line does not work:
“psychoJS.experiment.addData(‘score’, int(correctAcc == imageTest1))”
The problem lies in:
int(target pic in condition file == pic shown)
Unable to get the “score”:
Thank you for reading my question. Appreciate your answer and help.
One thing I’ve found is that Javascript seems less able to evaluate and assign at the same time. Perhaps you could edit your Python code to:
score = (correctAcc == imageTest1)
psychoJS.experiment.addData(‘score’, int(score))
or even
if correctAcc == imageTest1:
score = 1
else:
score = 0
psychoJS.experiment.addData(‘score’, score)
Best wishes,
Wakefield
1 Like
Ye1993
April 18, 2020, 10:43pm
3
Hi Wakefield, much appreciate your patience.
I’ve tried both ways as you suggested:
First way score = (correctAcc == imageTest1)
psychoJS.experiment.addData(‘score’, int(score))
This way works only when I delete “int ()”, the output in “score” column is TRUE or FALSE.
Adding “int()” will generate “NaN”
Second way
“if correctAcc == imageTest1:
score = 1
else:
score = 0
psychoJS.experiment.addData(‘score’, score)”
This code cannot be recognized by the coder (thus unable to generate “RT”, “clicked”, and “score”)
The error might be related to nested if statement;
So I tried the following ways
a. replacing the “if else statement” with the following form
*It does not work.
b. Wrting only “if- else” statement
*Seems to not work.
With no prior knowledge of syntax, I can only learn through trials and errors, and imitation, which leads to wrong syntax. Appreciate your patience.
Many thanks.
Ye
Ye1993
April 18, 2020, 10:55pm
4
Hi Wakefiled, I succeeded!
This is my code–round 6!
I copied the right syntax here if anyone with similar problem needs help in the future
if image_1.contains(mouse_record):
continueRoutine = False
psychoJS.experiment.addData ('RT', t)
psychoJS.experiment.addData('clicked', imageTest1)
if correctAcc == imageTest1 :
score = 1
else :
score = 0
psychoJS.experiment.addData('score', score)
elif image_2.contains(mouse_record):
continueRoutine = False
psychoJS.experiment.addData ('RT', t)
psychoJS.experiment.addData('clicked', imageTest2)
if correctAcc == imageTest2 :
score = 1
else :
score = 0
psychoJS.experiment.addData('score', score)
elif image_3.contains(mouse_record):
continueRoutine = False
psychoJS.experiment.addData ('RT', t)
psychoJS.experiment.addData('clicked', imageTest3)
if correctAcc == imageTest3 :
score = 1
else :
score = 0
psychoJS.experiment.addData('score', score)
elif image_4.contains(mouse_record):
continueRoutine = False
psychoJS.experiment.addData ('RT', t)
psychoJS.experiment.addData('clicked', imageTest4)
if correctAcc == imageTest4 :
score = 1
else :
score = 0
psychoJS.experiment.addData('score', score)
And IT WORKED!
Thank you so much for your help~! Stay well.
Ye
1 Like
Excellent.
Can you point to the aspect of my Python syntax that didn’t translate to working PsychoJS?
Best wishes,
Wakefield
Ye1993
April 19, 2020, 6:49pm
6
Thank you. Yes.
1. This python code cannot run, due to the format of the single quotation mark on “score” .
I copied and pasted yours, and the single quotation mark did not turn into purple.
Deleting the previous one, and retyping a new one will work.
2. This python code didn’t run because of the position of “if” and “else” .
Making the “if” “else” statement parallel works.
3. So, I changed the location of the inserted “if” and “else” in the previous wrong syntax, and then it worked.
Before:
After:
Hope it answered your question. Thanks for your help.
1 Like