psychopy.org | Reference | Downloads | Github

Hello world: instead of my intended text

URL of experiment: FoodVal [PsychoPy]

Description of the problem:

a variable - varmsg1 is coded to say ‘try again…’ or ‘well done…’.
However, now I am only getting ‘Hello world’’ but the loop function is intact

I think that your issue is that elseif doesn’t work in JavaScript (and you’ve written it else if). If you had used Auto translation then you would have discovered if A: elseif B: becomes if A {} else {if B {}}

Thank you so much @wakecarter
I have made the correction, still it is not working. My guess is, it is due to the nested loops since my ncorr1 is not getting reset to 0 after one round of practice.

What code do you use to reset it?

The inner pracLoop runs once. The outer practice_rounds, the nReps is set for 3. As seen in code_3 (set outside the inner loop, but inside the outer loop- HLPracfeedback2):
in begin experiment:
ncorr1 = 0;
eachResp = 0;
varmsg1 = “”;
PLoopTally = 0;

in begin routine:

for (eachResp=0; eachResp<psychoJS.experiment._trialsData.length; eachResp++)
{
if (‘HLPrac_key_resp.corr’ in psychoJS.experiment._trialsData[eachResp]) {
ncorr1 += psychoJS.experiment._trialsData[eachResp][‘HLPrac_key_resp.corr’];
}
}

if (PLoopTally >= 3)
{
varmsg1 = “Well done! Redirecting to the test trials.”;
practice_rounds.finished = true;
} else {if (ncorr1 >= 8) {
varmsg1 = “Well done! Redirecting to the test trials.”;
practice_rounds.finished = true;
} else {
varmsg1 = “Your accuracy is low. Let us practice that one more time! Redirecting to the practice trials.”;
practice_rounds.finished = false;
PLoopTally = PLoopTally + 1;
ncorr1 = 0;
}}

3 conditions:

  1. if the outer loop has run 3 times, then the practice rounds are terminated.
  2. If the outer loop has not run 3 times then:
    a. if the overall accuracy for that particular practice round is over 8 then the outer loop ends.
    b. I am using the variable PLoopTally to end the outer loop after 3 rounds. and under the last else function ncorr1 is supposed to reset if the other two conditions are not satisfies.

In Begin Routine you seem to be recounting all previous trials rather than just adding 1 if the current trial was correct.

If I was going to fix this for you, my first step would be to back translate everything into Python and use Auto translate code components.

I’m also wondering whether you are trying to increase the nReps of a loop that has already started.

1 Like