Stuck at "initialising the experiment" after removing "import random"

I am trying to test my experiment online, but nothing happens, instead it is stuck at “initializing experiment” screen. I have found through the forum and crib sheet that you cannot use import in pavlovia. I have removed the import statement from my experiment and still have the same issue. I have not been able to find what I would be replacing my import statement with or what I need to use if I cannot use the import random functions.

I have 3 lists that need to be randomized/shuffled. I am not sure how to do this in Javascript. Any advice is appreciated.

train_list = ['Delayed', 'Deferred', 'Oneback']
test1_list = ['Immediate', 'Delayed', 'Deferred', 'Oneback']
test2_list = ['Immediate', 'Delayed', 'Deferred', 'Oneback']
shuffle(train_list)
shuffle(test1_list)
shuffle(test2_list)
lasttrain = train_list[-1]
firsttest1 = test1_list[0]
lasttest1 = test1_list[-1]
firsttest2 = test2_list[0]
lasttest2 = test2_list[-1]
if lasttrain == firsttest1:
    while lasttrain == firsttest1:
        shuffle(test1_list)
if lasttest1 == firsttest2:
    while lasttest1 == firsttest2:
        shuffle(test2_list)

**Edit: I have also uploaded the experiment file in case it is helpful.
rein4.zip (6.5 MB)

Hello,

I don’t think that the code does what you intend to (or what I concluded you want to do). You are shuffling test1_list and test2_list but you are never resetting lasttrain and firsttrain. So they remain the same irrespective of shuffling the lists. So, you need to reset lasttrain and firsttrain in the while loop.

You create lasttest2, but never use it subsequently. Why?

Best wishes Jens

When I run it on my laptop not through pavlovia and have it print the lists they are shuffled. So I assume that it is working? But maybe there’s a more efficient way of doing so that I’m not familiar with. I used many shuffle/randomize methods and this was the only one I could get to work and it requires the import random library. But I’m reading I cannot use that import in pavlovia.
I’m not sure what you mean by resetting lasttrain?
I use the lasttest2 variable in a different routine.

I also have created a new experiment to test what part of my code may be causing the experiment to stop at “initialising the experiment” screen. Even if I make a new folder with a new builder experiment that is simply just text and keyboard press, it stops at the same screen. So I’m thinking it’s not my actual experiment and instead is something with my settings, maybe?

I was able to fix the issue. I had some of my code in the in Before Experiment tab, and moved it to the Begin Experiment tab and it now seems to be working online.

Hello

Well, yes the list are shuffled but given that you don‘t reset the variables in your while-loop they have the same value as before the while-loop.

Best wishes Jens

When I have the variables print in my data file they are the new values. I thought in Python order matters, so having the variables defined as those indexes after the lists are shuffled would mean they take on the index of the shuffled list? I am still learning Python so I am not always sure of the most proficient way of doing things.
Should I instead have something like:

new_train_list = shuffle(train_list)
new_test1_list = shuffle(test1_list)
new_test2_list = shuffle(test2_list
lasttrain = new_train_list[-1]
firsttest1 = new_test1_list[0]
lasttest1 = new_test1_list[-1]
firsttest2 = new_test2_list[0]
lasttest2 = new_test2_list[-1]

That is what I had tried first, but then I received multiple errors about attribute types and the variables not being subscript-able.

Hello

ok, I understand that you don’t want that lasttrain and firsttest1 are equal. In case that they are equal, you shuffle test1_list from which you draw firsttest1. In most cases your code will work because lasttrain and firsttest1 are different. So in case lasttrain and firsttest1 are equal, your while-loop shuffles test1_list but never assigns a test1_list[0] to firsttest1.

You can test this with the following code.

train_list = ['Delayed', 'Deferred', 'Oneback']
test1_list = ['Immediate', 'Delayed', 'Deferred', 'Oneback']
test2_list = ['Immediate', 'Delayed', 'Deferred', 'Oneback']
shuffle(train_list)
shuffle(test1_list)
shuffle(test2_list)
lasttrain = train_list[-1]
firsttest1 = test1_list[0]
lasttest1 = test1_list[-1]
firsttest2 = test2_list[0]
lasttest2 = test2_list[-1]
print("First: ", test1_list)
if lasttrain == firsttest1:
    print("if entered:")
    while lasttrain == firsttest1:
        shuffle(test1_list)
        firsttest1 = test1_list[0]
print("Second: ", test1_list)

Just create a new experiment with just a code-component, surround it by a loop with say 10 or 20 repetitions. You will see that in most cases, lasttrain and firsttest1 are different and the if-condition evaluates to false. The list marked by First: and Second: will be identical. You will also see that sometimes if evaluates to true and the while-loop is executed. In this case, the lists marked by First: and Second: will different. Now in the next step, delete the line

firsttest1 = test1_list[0]

and rerun the experiment. You might have to kill the experiment at some point in time because the while-condition always evaluates as true. I have two screens which allow me to monitor the Stdout. So, I see when the if-construction evaluates as true and the program gets stuck in the while loop. If you only have one monitor, write the output to a file, kill the experiment and check the written output.

Best wishes Jens

1 Like

I see! I originally misunderstood what you meant, my apologies.
Yes, I failed to reset my variables in the case that my lists need to re-shuffle!

I have made the changes below. I think this should fix that problem?

shuffle(train_list)
shuffle(test1_list)
shuffle(test2_list)
lasttrain = train_list[-1]
firsttest1 = test1_list[0]
lasttest1 = test1_list[-1]
firsttest2 = test2_list[0]
if lasttrain == firsttest1:
    while lasttrain == firsttest1:
        shuffle(test1_list)
        firsttest1 = test1_list[0]
        lasttest1 = test1_list[-1]

if lasttest1 == firsttest2:
    while lasttest1 == firsttest2:
        shuffle(test2_list)
        firsttest2 = test2_list[0]

Hello,

yes, this will work. As an alternative, you reset only firsttest1 or lasttest1 :wink .

Best wishes Jens