Pavlovia stuck in ititializing

URL of experiment:

Hi all

I know it’s not a new issue and has to do with the Java code (since it worked without it), but I cannot figure out where my mistake is. I am using the latest version of PsychPy and have Auto->JS version.
Please find the few lines of code I used and please help me find my problem.


thousand thanks!
My experiment is

https://run.pavlovia.org/Katharina_Kuehne/it_co/html/?__pilotToken=c74d97b01eae257e44aa9d5bade97baf&__oauthToken=477e9068ceed87e2cd56f6f31dd5b87650c4fcc8649ee8a1604f65091601d430

The code (
is
in the beginnig:

from numpy.random import choice

import {choice} from ‘numpy/random’;


A feedback code:


msg=’’
msg = “”;

if not key_resp_sentence.keys :
msg = ‘Troppo lento!’
elif key_resp_sentence.corr:
msg=“Giusto!”
else:
msg=“Falso!”

if ((! key_resp_sentence.keys)) {
msg = “Troppo lento!”;
} else {
if (key_resp_sentence.corr) {
msg = “Giusto!”;
} else {
msg = “Falso!”;
}
}

I’m not sure whether this is the reason for this specific error, but there’s no numpy in javascript, so you won’t be able to import it outside of the python version of your experiment.

If you need a function that does something similar to random.choice in numpy, here is a simple one I use in a couple of my experiments:

function sample(target, nSamples){
  function getRandomArbitrary(min, max) {
    return Math.random() * (max - min) + min;
    }
    var tmp = [];
    while (tmp.length < nSamples){
      var x = Math.floor(getRandomArbitrary(0, target.length));
      if (!tmp.includes(x)){
        tmp.push(x);
      }
    }
    return(subset(target, tmp));
}

It relies on this subset function to work, so you would need to include this too:

function subset(target, elements){
  var i;
  var tmp = [];
  for (i=0; i < elements.length; i++){
    tmp.push(target[elements[i]]);
  }
  return(tmp);
}

(I am far from a javascript expert, so there may be much simpler ways to accomplish the same thing, but this is good enough for my purposes.)

Thank you ever so much for your quick reply. Yes, I do need this function, because I have to shuffle between blocks or actually 4 different files. So it is very very essential.

I am very bad at programming :slight_smile: so please could you explain where I could paste this code?

I want to run the experiment both off- and online.

Thanks again.

You can’t use import

Have a look at my crib sheet for a shuffle function.

If you need more explanation, please let me know.

Best wishes,

Wakefield

1 Like

Dear Wakefield,

thank you for your suggestion. The thing is, I do not only need the shuffle, but also choise.

My loop is a bit complicated:

I have two kinds of stories, priv and pub (10 each) and two kinds of sentences priv and pub (60 each)
They should belong to each other as to the quality pub or priv. Then I have a catch task with a separate file.
I want to present 1 story, 6 belonging sentences, math task, 1 story, 6 sentences etc…So wile only choosing 6 random out of 60, I need to shuffle the stories (and thus, the qualitues)

loop_strory loop_sentence outer_loop

I solved that very well with the numpy function but now I am lost.

I would really appreciate if you had a suggestion.
Many thanks

Katharina

In principle could you shuffle the numbers 0 to 59 and then create a new array from the first 10 entries?

I’m on my phone doing a puzzle with my 2 year old so a little distracted.

What I do for something similar is have loops loading items into arrays and then have my trials loop taking items from these arrays instead of the excel files.

Greetings to your child :slight_smile:

I am very new to PsychPy so I exuse my naive questions. Do you mean creating something like a dictionary? I am not sure how I can do it.
Sorry for bothering

I have now changed the code

Before every presentation I have a code

randomRowList = list(range(60))
shuffle(randomRowList)

And then in Select Rows

$[randomRowList.pop()]

I works fine offline but on pavlovia it returns an error: Range is not defined

I guess it is because I have to define this variable in JS but I have no idea how. This offline-online conversion seems to be quite tricky still, in spite of the automatic Python-JS translation.

Many thanks in advance!

Why didn’t you use just $randomRowList ?

I’m not familiar with pop

You could count the loop and end it early (try not ending it to check the code first).

Many thanks for your reply.
I want the choose 6 rows every time, but they should not repeat in blocks. So every single collection of 6 rows is unique.

I think JS doesnt understand the range function…

So basically, it doesnt like

randomRowList = list(range(60))
shuffle(randomRowList)

its translated in JS in a wrong way

If I end the loop earlier, I think the same items can come up in the next run, right?

Is there a way i can import random in JS?

Many thanks

If you address items in the array using a variable which you increment manually rather than trials.thisN then you would get the first 10 items the first time and the second 10 items the second time, etc.

Use different variables which increment at different rates to address your different arrays.

Best wishes,

Wakefield

Thank you ever so much for your reply. I really appreciate your help and support!

I begin experiment of one of my my loops (I have three of them) I wrote

myCount1 = 0

in JS: myCount1 = 0;

Further, in start routine

myCount1 = myCount1 + 1
if myCount1 == 6:
loop2.finished = True

JS:

myCount1 = (myCount1 + 1);
if ((myCount1 === 6)) {
loop2.finished = true;
}

I seems to be working on the desktop, but NOT only. So it just continues showing all the 60 items.
And sometimes I get an error ONLINE: MyCount1 is not defined.

What am I doing wrong? Thanks again!

Edit both to change loop2 in the JS code to trials but leave it as loop2 in the Python.

You’ll need to redo this every time you edit that Python code.

ahh I see
I changed that but now I get

ReferenceError: myCount1 is not defined

After updating many times and restarting it now stuck after trial 6, just stops and does not do anything

I JS I have

myCount1 = (myCount1 + 1);
if ((myCount1 > 5)) {
trials.finished = true;
}

Do you have myCount1=0 in the Begin Experiment code block?

It might be that this issue is that all of your loops are getting finished at the same time.

You could set up this experiment with one loop. Before your trials routine you could have a routine that works out which loop type you are in.

However, I’ve just noticed that you can a routine called trials. Since JS thinks that the loop is called trials that’s not going to end well.

The default trial name is trial singular.

many thanks! I am very sorry to take so much of your time :frowning:

Well, ofline it works fine.

Yes, I have myCount1 = o in JS myCount1 = 0;

Thanks for pointing that out with trials, I have changed the name but no better :slight_smile:

I think JS cant decide which trials is this trials because all the loops are called trials…

This PPT to JS transfer seems to be very tricky

If you address items in the array using a variable which you increment manually rather than trials.thisN then you would get the first 10 items the first time and the second 10 items the second time, etc.

Use different variables which increment at different rates to address your different arrays.

Could you expand on that, please? The counter picks the same items every other run. Many thanks!

Hi.

I’ve just written an experiment first draft that has an outer loop which manually increments a variable instead of using trials_2.thisN

It’s set to public and available from https://pavlovia.org/Wake/self-reference-matching