You need to explain to us exactly what you mean by this.
I dont understand how to link my code to the builder… I wrote the code in the code component in ‘each frame’
Thats’s my new code, I did some changes in it.
from random import choice, shuffle import pandas as pd num = 60 letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'] my_list = [choice(letters), choice(letters)] probab = list(range(num - 2)) shuffle(probab) # We want 20% of the letters to repeat the letter 2 letters back pourc = 20 repeatnum = num * pourc // 100 for i in probab: ch = prev = my_list[-2] if i >= repeatnum: while ch == prev: ch = choice(letters) my_list.append(ch)
I added a text component and named it $my_list
I get this error :
text=my_list, NameError: name 'my_list' is not defined
As the name on the tab implies, that code will run on every frame (i.e. on every screen refresh), which is typically 60 times per second. That isn’t what you want.
Think about when you want the code to run, and put each part in the appropriate tab. e.g. imports should happen only once, so those lines belong in the “Begin Experiment” tab.
But in your case, these libraries are already imported by Builder, so you can (and should delete them). In particular, Builder imports
numpy.random, so you importing it from Python’s standard
random library will cause the intended ones to be overwritten.
I guess some other code should only run at the beginning of each trial, and so on.
It’s working, but I get the complet list at the same time.
It is possible to separate it ? I want each letter to be on a different screen.
I thought that if I put $mylist in the text component, it would be like a variable and show each letter one after the other.
Computers do what you tell them to do. If you ask it to display a list of items, that list will be displayed. If you want to step through the items of the list and display them one at a time, then that is quite a different thing and needs to be implemented explicitly: computers can’t guess what you want to achieve, they only take you literally.
I think you need to draw a flow chart of what you want to implement and when. The design of the flow panel (i.e. how many (possibly nested) loops) and what you need any code to do and when, will fall naturally out of that.
Thanks Michael for your help!
I’m sorry I don’t understand what you mean
I read many thing about the flow, but it all seems to be related to an csv files or an excel file with the conditions. I understand how to do that, but in this case, I want the loop to see in the list I created in the code component.
Is there a way to link both of them?