Description of the problem:
Hello,everyone.
I am writing an experiment program in psychopy’s builder mode. In the code component of our experiment program, I need to use the shuffle and choice functions from the random or numpy library to help me shuffle a list or randomly select an element from a list. When I compiled the experimental program into js scripts and uploaded them to the online experimental platform, they often failed to run properly online because they could not recognize numpy or import other libraries. Since I know almost nothing about js language, I would like to know how to implement the functions of shuffle and choice similar to Pyhton in online experiments?
Best regards!
Hello,
Instead of using random.shuffle(), you can simply use shuffle(). It will simply translate itself to util.shuffle(); which is a correct randomization function that works in PsychoJs.
Thanks for your useful advice, the shuffle function can work properly now, but I came across another question, it said “TypeError: 5 is read-only”.
Is it resulted by the list.remove?
Thanks a lot for your advice!
I found that the problem was that the js language couldn’t combine two arrays like python, so I used python append (which automatically converts to js push) to solve this problem, but I now have another problem, I have tried several js language methods to delete the specified element in the array,
However, there is no way to remove specified elements from a list like python’s remove function, including splice, filter, etc. filter removes the specified element from the array, but according to my online experiments, it removes not the element I gave it, but another element in the list, which is very confusing to me.
Could you please give me some suggestions on the code? I just want to be able to remove a specified element from an array in a js script in the same way that remove can do in python.
As shown in the code, I want to remove the tarcolor element from the colors list.