To distinguish exactly what the problem is, some logging might be helpful. Is it that trials.finished=true isnāt doing anything? Or is it that the condition isnāt being met?
I recommend the following for your JS code:
myCount1 = myCount1 + 1;
console.log(myCount1);
if (myCount1 > 5){
console.log("Setting trials.finished to true");
trials.finished = true;
}
These messages will appear in your browserās JavaScript console, which you can find in Chrome by going to View -> Developer. That will tell you if MyCount1 is updating correctly, and if the condition is ever being met. The big thing to watch out for is if you see multiple instances of the message āSetting trials.finished to trueā, because that would mean itās failing to exit the loop correctly.
Looking back at the other thread you also have a lot of nested loops. Keep in mind that trials.finished will always apply to the most proximal loop to the trial this code is in. You may want to look at dummy trials if you are trying to get out of multiple layers of nested loops. See here: Loop.finished not working
Thank you for your quick reply.
I am sorry for my maybe stupid question, but what is the corrrect tab to put the specific codes (setting to 0, counting and trials.finished part?) If I put the counter in Begin experiment tab even offline it goes through it only once (I need to repeat the loop 10 times with different sets of 6 stimuli from a big list).
If there were some random option for pavlovia to take 6 random items from the list, it would be perfect! The choice option worked well offline but not on pavlovia.
The simplest solution is probably to put it once in begin experiment, and then a second time in the conditional that ends the loop. So, in begin experiment:
The problem is it does not reset. Even offline. The first time it goes all right 6 trials and stop
and the next time it still things that the myCount is > 5 which is true if we continue counting, and only shows 1 trail etc
Keep in mind that the JS code and the Python code are different, and if youāre running locally youāre only seeing the Python code. Did you put myCount1 = 0 into the same conditional statement in your Python code?
Iām afraid I need more information about what exactly you have set up. Can you link your code repository on pavlovia (go to āview codeā and link the page there, and go to settings -> general -> permissions and set it to public) or upload your experiment here so I can have a look at it? I donāt have enough information right now to figure out why it might not be working.
I present a story (alternatively from one of two files), 6 sentences with feedback (again alternately from one of two files belonging to the story), and a math task.
The idea behind this was that it resets the counter when the condition is met. You want that in both your JS and your Python code to test my solution. So, in your Python code:
if myCount1 > 5:
loop2.finished = True
myCount = 0
You want this particular block of code at āend routineā in your āfeedbackā trial type.
In your web browser, when it gets stuck on initializing, open up the JavaScript console. (In Chrome, you can find this by going to View -> Developer.) This should give you a more informative error message about why itās getting stuck.
Interesting. It copied the quotation marks incorrectly.
In PsychoPy in the code component that has this line:
console.log("Setting trials.finished to true");
delete the quotation marks and replace them with single quotes. Donāt copy and paste from here, type them in. The issue is that it somehow filled the code component in with āeducatedā quotes that are different shape at the beginning and end rather than plain quotes, and JS doesnāt know how to read educated quotes.
Anything in red, and anything that references ācotidie_de1_withcode.jsā and gives a line number, ideally, but whatever you can share may be helpful. That said, it sounds like it is successfully breaking after six trials.
6
cotidie_de1_withcode.js:2684 Setting trials.finished to true
core-2020.1.js:1437 TypeError: Object.keys is not a function
at ExperimentHandler.isEntryEmpty (data-2020.1.js:33)
at Scheduler._currentTask (cotidie_de1_withcode.js:3007)
at Scheduler._runNextTasks (util-2020.1.js:1091)
at Scheduler._runNextTasks (util-2020.1.js:1094)
at Scheduler._runNextTasks (util-2020.1.js:1094)
at Scheduler._runNextTasks (util-2020.1.js:1094)
at Scheduler._runNextTasks (util-2020.1.js:1094)
at update (util-2020.1.js:1058)
window.onerror @ core-2020.1.js:1437
data-2020.1.js:33 Uncaught TypeError: Object.keys is not a function
at ExperimentHandler.isEntryEmpty (data-2020.1.js:33)
at Scheduler._currentTask (cotidie_de1_withcode.js:3007)
at Scheduler._runNextTasks (util-2020.1.js:1091)
at Scheduler._runNextTasks (util-2020.1.js:1094)
at Scheduler._runNextTasks (util-2020.1.js:1094)
at Scheduler._runNextTasks (util-2020.1.js:1094)
at Scheduler._runNextTasks (util-2020.1.js:1094)
at update (util-2020.1.js:1058)
jquery.min.js:2 Uncaught TypeError: Object is not a function
at Function.makeArray (jquery.min.js:2)
at new n.fn.init (jquery.min.js:2)
at n (jquery.min.js:2)
at t..._on (jquery-ui.min.js:6)
at t..._classes (jquery-ui.min.js:6)
at t..._toggleClass (jquery-ui.min.js:6)
at t..._removeClass (jquery-ui.min.js:6)
at n.fn.init. (jquery-ui.min.js:6)
at Function.each (jquery.min.js:2)
at t...destroy (jquery-ui.min.js:6)
core-2020.1.js:1437 null
window.onerror @ core-2020.1.js:1437
Tone.min.js:1 Uncaught TypeError: Cannot read property ātoStringā of undefined
at Function.n.isObject (Tone.min.js:1)
at Function.n.defaultArg (Tone.min.js:1)
at s.default.TimelineState.s.default.Timeline._search (Tone.min.js:1)
at s.default.TimelineState.s.default.Timeline.forEachBetween (Tone.min.js:1)
at s.default.Clock._loop (Tone.min.js:1)
at s.default.Context.s.default.Emitter.emit (Tone.min.js:1)
jquery.min.js:2 Uncaught TypeError: Object is not a function
at Function.makeArray (jquery.min.js:2)
at new n.fn.init (jquery.min.js:2)
at n (jquery.min.js:2)
at t..._on (jquery-ui.min.js:6)
at t..._classes (jquery-ui.min.js:6)
at t..._toggleClass (jquery-ui.min.js:6)
at t..._removeClass (jquery-ui.min.js:6)
at n.fn.init. (jquery-ui.min.js:6)
at Function.each (jquery.min.js:2)
at t...destroy (jquery-ui.min.js:6)
core-2020.1.js:1437 null