![]() This is a good example of converting variable “types” in python: We can add a Text stimulus, and in the Text field write str(t) ( t is a special variable that lives under the hood of PsychoPy, it indicates the time since the trial started) then make sure to set the field Each frame. To show the participant the time into a trial, we don’t even need a code component. Hint: you can get the average of a list using average Make a list to track response time over trials and tell participants their average response time at the end. ![]() Set the color of the trial-by-trial feedback to be green if the response is correct and red if incorrect.ĭownload the images here to show a celebration image if the answer is correct, and a sad face if incorrect on each trial. addData ( 'percent_correct', ( sum ( accuracy_list ) / len ( accuracy_list )) * 100 ) Exercise (20 mins) ¶ By default, python code will be transpiled into JavaScript.Ī Code Component allows you to add Python (and now JS) code at 6 different points in the script:Įach entry of your Routine has multiple Components and their code /for each part of the experiment/ is run in the order of the components.ĭo you want you custom code executed before or after your stimulus? You can add code in either python or JavaScript (JS). This goes to the next step in integrating code with your experiment. Make an object more interesting for participants (e.g. Make an object move to make the task harder Making things dynamic could allow you to, for instance: a shape that tracked the mouse by setting the shape position to be mouse.getPos() things change their attributes in time).Į.g. Using code as arguments allows us to easily make stimuli ‘dynamic’ (i.e. If you actually need a dollar symbol to be in your text, do: Set a text object to have text "ABC" and have it update every repeat You can use this as more than a variable from your conditions file e.g.: Most dialog entries have the option to take raw Python code if you start your entry with $ (or have that by default). Hacking the script is useful to see how things work but it’s better to add your edits back into the Builder view. If you do your changes will NOT be reflected back in the Builder experiment. You could tweak this code and see the effects your edits have on the running of the experiment. You could save and run this exported script (that’s what Builder does each time you press run). T is always the current time in sec since the start of the Routine to find out what variables a Builder experiment ‘knows’ about e.g.:.trial is over)īuilder doesn’t know your intentions so plans for everything Compiling your experiment to python or JavaScript ¶Ī first step to combining your code with a Builder is to compile a builder script to coder and peek what’s “under the hood”.Ĭompare this with scripts you may have written:ĭetermine whether all the components are finished (i.e. Being able to write code helps you do things that a graphical interface can’t. Generating ‘standard’ paradigms in Builder is generally easier than writing the code yourself. Extending Builder with code ¶ Using Builder to create your experiment ¶
0 Comments
Leave a Reply. |