Feedback messages fail to display in timing task

Hi,

I’m trying to add feedback to a timing task, but the two feedback messages I want to give the user are not displaying when I run the task. I’ve written some custom code that’s been added to Psychopy as a new routine. Under Code Properties, I have the following:

Begin Experiment:

msg='great'
msg=''

Begin Routine:

x=key_resp_3.rt/intervals
y=abs(key_resp_3.rt-intervals)

if y<=x/6.7:
    msg="Great"
elif y>x/6.7:
    msg=" "

I want the first message to display when y is less than or = to the statement (1st condition) and no message to display (2nd condition) if it is more. Note that intervals is a variable that I created.

In the custom text GUI, I wrote $msg for the text and set it for a duration of 3 seconds. Not sure why the messages won’t display.

Is it a syntax error? Does anyone have any ideas?

Thanks,
Farah

There are a number of things that could be happening. For a start, you have created msg at the start of the experiment and given it a value of '' (note that this immediately overrides the previous value of 'great', so there is no point in having both of those statements there). If the value of msg doesn’t get updated, then nothing will be seen on screen. There are several possible reasons why the text won’t get updated:

  • you might have set the text field to be ‘constant’. That way, it gets the initial blank value of msg and never changes. Ensure you set it to update every repeat so it gets a new value on every trial.
  • y<=x/6.7 never evaluates to True. You can check this by printing the output of the expression to make sure the calculation is giving values you expect.

Secondly, the order of components is important. The code component must be above the text component so that a new value is calculated for msg before it gets used by the text component. Otherwise, the displayed value of msg will always lag behind by one trial.

No, a syntax error gets reported to you in an error message, and will stop the experiment running. A syntax error is Python telling you “I don’t even understand this code”. These errors are almost always easy to fix. Unfortunately, most programming bugs are when Python understands our code perfectly, but it’s just that the code doesn’t do what we intended it to do.

Thanks, Micheal. This is helpful. Setting the text to every repeat helped. I have follow up questions.

What’s the best way to change y<=x/6.7 to a true statement?

I have the code component above the text in the GUIs I’m using. Should I also reorder the if/elif expressions under "Begin Experiment’ and write the messages under “Begin Routine” then?

y <= x/6.7

Will always evaluate to either True or False. Which it is depends on the values of x and y. Only you will know what ranges those variables take and whether the calculation does what it should.

Code in the Begin Experiment tab is executed only once, before your trials have started, so it isn’t a suitable place to put code that needs to respond to variables that update during the experiment.