MacOS Catalina, Psychopy 2021.2.3
An old and working version of a programme incorporated a counter that printed updated responses on the screen using a text component, with the following in the text box:
$“Food:%.0f”
%TotalFood
where TotalFood is constantly updated. This used to print “Food” and then the value of the variable underneath it. This no longer works - it gives a syntax error (Python syntax error in field ‘text’). Moreover, I can’t find any instructions for printing the value of a variable on the screen – everything I’ve tried that is recognised just prints out the variable name. This has to be super-simple, so sorry!
Update – I have discovered that while
$“Food:%.0f”
%TotalFood
is not recognised
$“%.0f” %TotalDrink
is, and updates as required. How to make it print the word Food as well is beyond me, but easy to work around. So the new question is: are different text components required to mix printing of words and variable values? This is now curiosity rather than desperation… ; )
Hello,
one possible solution is mentioned in the documentation. You first create your message text and store it in a variable, then you refer to this variable in your text-component.
message = 'The result is %s' %(text)
Best wishes Jens
I think you’re assuming a level of knowledge I don’t have. Plus I tried copying your text verbatim into a code component and it gave me a syntax error - fix Python code!
Hello,
I just copy&pasted the text in a code-component. No syntax error in my case.
Best wishes Jens
I tried again typing it de novo, same thing. However, it does this in one programme but not in another. All I can guess is that the one where is doesn’t work was written in an older version of Psychopy, and that is somehow making a difference!
Hello
which version is not functioning? I am currently using 2022.2.5. but I have used this kind of formatting for at least 3 years.
Best wishes Jens
They are both now in the same version of Psychopy, details of which I posted at the top of my message. But they were written in different versions - and the one that’s playing up is older. It’s fine, I can work round it, but it’s weird!