Coding Weighted Probability Feedback

Description of the problem:

Hello everyone,

I am designing a study in which people have to rate the beauty of faces on a scale of 1-7 (slider). Then I present participants with the fake average rating of their peers, and ask them to rate the face again to see if they change their minds.

There are rules to the fake average ratings - if the participant initially rates the face as 1 or 2, then the fake external rating has a 50% chance of being the same as that initial rating, a 25% chance of being 2 points higher, and a 25% chance of being 3 points higher. Vice versa for initial ratings of 6 or 7. For initial ratings of 3, 4, or 5, the rules are much the same, but external ratings have an equal chance of being higher or lower.

I have managed to code this into a code component in PsychoPy builder - it is rather convoluted (as I am quite new to this) but it works:


my_list = [1, 2, 3, 4, 5, 6, 7]
initial_rating = InitialGoodnessSlider.getRating()
test = ‘’
ExternalGoodnessRating = ‘’
import random

if(initial_rating == 1):
test = str(random.choices(my_list, weights = [2, 0, 1, 1, 0, 0, 0], k = 1))
x = test.strip(’[]’)
y = str(x)
z = str("Others rated this person: ")
ExternalGoodnessRating = z + y


(And then several “elif” functions for the other values the initial rating could be. I then print this above variable in a text component.)

However, when I transfer this experiment onto Pavlovia, it does not get past the initiation screen.

From what I have read, I am quite sure that this is due to the “import random” function I used. However, I am unable to take that out, as the whole thing will not work.

My question is this; how can I code this weighted probability feedback mechanism in a way that is compatible with Pavlovia? I am completely new to Javascript so I am struggling.

Thank you very much for your time. I hope this all makes sense.
Marcus