Alternative to constructor row select function that works in pavlovia

Hello guys

Can anyone help me, I’m new here and I understand little about programming, in this case I use psychopy version 2021.2.3 and in the constructor I use the selected lines function: $random(1)*10 which serves me locally, but when loading some experiment in pavlovia an error occurs, I saw that it is not supported by pavlovia?

In this case, I want the loop to play only one song from a set of ten songs in the Excel spreadsheet. I’m grateful if anyone can help!

Hi

Have you checked JavaScript Random (w3schools.com)

1 Like

Hello,

Thanks for the suggestion! I tried to use the Math.random() function in JS code, to bypass the selected lines function in Py, however, the error appears that the “name ‘Math’ is not defined”, but, I can’t use “import” because, it doesn’t work online. Do you have any idea how I can solve this problem?

Math.random() should definetely work. Could you make your experiment available to download?

There is also util.randint(), which, however, also uses Math internally.

I think the issue may be that you are putting Python code into the loop definition. I would recommend creating an array of the random rows you want in a code component and then using that variable name in the loop definition.

Are you wanting a random row from 0 to 9.

If so, you could try:

x = randint(0,10)
userows = str(x) + ':' + str(x+1)

Hi Ajus!

I can provide … any help is welcome. Can you explain me how to share it with you?

Thanks!

Hey !

I will use your suggestion and get back to you if it worked. Thanks!