| Reference | Downloads | Github

If and else statements

macOS here, hopefully, could get an answer. I’m entirely new to PsychoPy and my python knowledge is limited so please be bear with me

I’m working on builder mode and have an experiment that requires a key input (simple left or right). So for example, choosing heads or tails… left is head and right is tails, so if key_input ‘left’ and Result == Heads print (“you won”) and vice-versa if they lost. I’m unsure as to how such code would look like.

The judgment of correct vs incorrect could probably be handled without code at all, just by having a column in your conditions file that gives the correct answer for that trial, e.g. a file that looks like this:

coin    correct_answer
Head    left
Tails   right

and in your keyboard component, select “Store correct” and put $correct_answer in the “Correct answer” field. An advantage of using the keyboard component to do this is that the result is automatically stored in the data file for you.

Have you watched the Stroop task tutorial, which covers this sort of stuff?

Then to give conditional feedback, just put something like this in the “begin routine” tab of a code component of the next routine, by asking the keyboard component whether it recorded a judgment of correct or not:

if your_keyboard_component_name.corr:
    feedback = 'Well done!!'
    feedback = 'Rubbish!!🤦‍♂️'

and then put $feedback in the text field of a text stimulus on that routine, set to update “every repeat”. make sure the code component is above the text component, so that the latter gets to refer to the latest value of the feedback variable.

1 Like

@Adrian_Rivera, You can find an example with more detail in this topic (check the last post of the topic). It is basically the same as Michael’s method.