| Reference | Downloads | Github

Exit a loop on pavlovia

It’s setting trials.finished correctly and it is indeed trying to end the loop using the shared code that ends loops, but it’s breaking when checking whether the results of the loop are empty or not and trying to save it. That’s unexpected.

I’m going to create a copy of your experiment for myself and start tinkering, I’ll update you if I figure something out.

Thank you ever so much, this is extremely generous of you! Thousand thanks!
We are expected to start testing this week and since it all worked offline I was kind of relaxed :smiley: and now I am desperate :slight_smile:

Well, that ended up being much more interesting than I expected it to be. This is broken in a truly fascinating way, which I know isn’t much help to you right now, but I feel totally licensed in calling in @jon, @apitiot, @dvbridges, to help me figure out what is going on.

First of all, the spew of jquery error messages is unrelated, and will go away if you refresh the page after loading it once. I don’t know why, but it seems largely unrelated to the loop issue.

There’s another unrelated thing I picked up that you will want to fix just in general: In your feedback trial, for the code that controls the feedback, it will get stuck on the message ‘Zu langsam!’ after it’s displayed for the first time, because it’s never reset to blank. Also it won’t end the trial correctly unless continueRoutine = False is moved to the “each frame” tab. You can see my changes here:

Now for the problem we actually started with: I’ve pretty well isolated where it’s going wrong, but I have no idea why, and it’s really not doing what I thought it was. The issue is on this line of the standard end-loop function that PsychoPy builds into every experiment:

if (psychoJS.experiment.isEntryEmpty())

the error is being generated by isEntryEmpty() itself on this line:

return (Object.keys(this._currentTrialData).length > 0);

Specifically, it claims that “Object.keys is not a function”. I don’t know the under-the-hood bit of the experimentHandler well enough to understand exactly what it’s looking for here, but clearly it’s getting something else. Notably, this happens even if I force it to use a conditions file that ends normally after it cycles through the whole file.

That is, if I disable this code component completely and use a condition file with only 4 entries, it will still break in this exact same way after 4 repeats, so it’s not the code component at all! Ending this loop, no matter how you do it, is crashing this experiment and I do not understand why. Even weirder, there’s a practice loop earlier in the experiment that, in my modification, is structurally identical and it has none of these problems.

I’m hoping someone else has some insights as to what’s going on with experimentHandler there, but I’m sorry to say I’m out of ideas.

oh wow, you’ve done so much!

Maybe the difference is that the practice trial uses a true excel file and this trial uses a $conds from a list of files.

I thought of that, actually, but it happens even if I replace $conds with a specific excel file.

So wierd

@jonathan.kominsky @Katharina_Kuhne, this is not actually a coding error, but a problem with the conditions files called “sentence_gerpriv” and “sentence_gerpub”. Its not obvious, but you have a column/variable called “Object”, which has overwritten the JavaScript keyword of Object. If you change the column name to something else, e.g., “sentenceobj” then the "Object.keys" error should disappear (it did on my version).

1 Like

Ah, good catch! I’ve seen that before too, I should have known. Well, at least we found a solution.

Omg, thank you ever so much, it’s such a sublime error! I will immediately try out this and the feedback correction! I am so thankful for your help!

I actually had no problems with this feedback, it showed all right. Or do you mean on pavlovia?

The error has disappeared!! JUHU!

But unfortunately, the randomization does not work properly :frowning: It repeats some sentences 4 times and some do not come at all. The same is with stories. And it also did not record the story variable in the pilot file. So basically, its random with replacement. I need random without replacement :frowning:

Is there maybe some other way to choose random items from iterative lists on pavlovia? Choice worked very well offline.

I my earlier offline version I also had a code in presentation

randomRowList = list(range(60))

And then in Select Rows


I seemed to be working but not on pavlovia

I appreciate your help and support, sorry for taking so much of your time!

I entered this code now on PHP

ranList1 = list(range(60))

And on the JS side

function shuffle(a) { var j, x, i; for (i = a.length - 1; i > 0; i–) { j = Math.floor(Math.random() * (i + 1)); x = a[i]; a[i] = a[j]; a[j] = x; } return a;}

ranList1 = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59]


with Select rows $[ranList1.pop()]

Seems to be working offline but on pavlovia it just presents SINGLE letters (of something)

@Katharina_Kuhne, equivalent methods in JavaScript might be something like:

// Create a range of values between 0 and 60 (not inclusive of 60)
arr = [...Array(60).keys()];

// Shuffle the array

// pop value from array

many thanks for your answer. I appreciate you taking time for me.

Unfortunately it still presents this instead of the story and the sentence

This is this project now

That related to how the rows are being indexed in your loop - rather than looping through rows, it is looping through the text in one row that has been selected - this is not normal, but perhaps there is something odd going on with the combination of nested loops. For your loop2, you need to pop a value into a variable (currentRow = arr.pop()), and then use it in an array to index the rows e.g., [currentRow, currentRow].

Take a look at the link, and see if it is working as it should.

If so, download the repo here

Many thanks!

I think I works for the sentences bt not for the stories or math tasks (I think you just did not change them) :slight_smile: Oh if I could only fix it today!!! :star_struck: :star_struck:

Exuse my very stupid question, but where do these lines go to?
currentRow = arr.pop() ),

[currentRow, currentRow]` .

Again I am very thankful for your time and effort.

Take a look at the repo if you can, all the code is there. If not, see the attached.

cotidie_de1_NEW (copy).psyexp (126.1 KB)

Thank you ever so much.

Indeed, the sentences behave all right, but the catch trials and story not. The math task does not show anything but the operator sign plus or minus.

I also have RangeError: Invalid array length error for the story (there are 10 in each file), I tried Array(11) and Array(10) both…

I also noticed you changed the loops to sequential and in some you have $[currentRow, currentRow] .
and sometimes just $currentRow - what is the difference?

Exuse taking so much of your time!

Ok, I am not sure how they are supposed to behave, so its difficult to know what is happening.

Yes, that error has occurred because the array that you are popping shrinks each time you pop until eventually an error occurs because you are feeding an undefined value to the loop selectRows field, so to overcome this, I moved the array creation into the begin routine tab of the code component, but then moved the code component called “code_shuf_story” into the parent loop of loop2, i.e., loop3. That way, a new array is created each time the outer loop runs, so you start with a fresh array on each block.

Something I forgot to mention, if you want random without replacement, you have to change the loop2 randomisation to “Sequence”, because the randomisation is handled by the shuffling of the arrays, rather than the loop. I think the use of arrays to control loops may be unnecessary, since you can use the loop handler to randomize your arrays, and then exit the loop after so many iterations using code. I guess you may also want no repetitions across blocks, which will mean that you cannot use the method of refreshing the array on each iteration of the outer blocks, and the array will need to only be created at the beginning of the experiment, as it was in the first place before I changed it.

A good strategy to get this working, is to break your task down into separate sub tasks i.e., separate Builder files, get those working online individually, and then integrate them into one builder file when you know each subtask works correctly. This will help you debug the task, because if the task fails you know which step is responsible.

Well I used to have a code to stop the loop after 6 trials but it repeated the trials so that the same row appeared 5 times in different blocks. So I abandoned this idea. Maybe the order also should have been set as sequential?

Indeed, there need to be 1 story, 6 sentences and 1 math task in every iteration without replacement.
This is such a difficult task in pavlovia, although it seems to work offline.

The problem is that I believe once I test them separate it’s not the same as when they are in the dependent nested loops.

I learned here how (pop) behaves, this is actually exactly what I want.!topic/psychopy-users/rDvqDUgmYEg