[solved] forcing newlines in loop variables and/or sketchpad text elements
How does one force newlines in text strings that in loop variables or sketchpad text elements?
I've tried using \n in normal strings and triple quotes for multi-line strings in the python script editor. Inserting the Unicode equivalent (U+000A) works, but that seems like a weird work-around.
Comments
Hi Pmheider,
I'm afraid there's no really elegant solution for this, so I opened up a feature request: https://github.com/smathot/OpenSesame/issues/69
But life can get easier with a little inline_script. Let's say that we use '_BR_' to indicate a newline in loop variables, like so:
You can convert this into the proper unicode symbol by putting a small piece of code in the prepare phase of an inline_script at the start of the sequence under the loop.
Whether this will work in a sketchpad depends on the back-end. Under the legacy back-end, the newline will simply be treated as an unknown symbol. Under psycho it should work.
Thanks for bringing this to my attenion!
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
When I first figured out that Unicode would work, I wrote a similar script to deal with newlines in the items.
Unfortunately, a funny thing happens to newlines and U+000A's in the editor. If I save and close an inline_script containing code like this:
reNewlines = re.compile(r'\n')
I will get an error message because of an unclosed quote. That seems odd until you go back to the inline_script to check the problem. Here's what the code looks like now:
reNewlines = re.compile(r'
')
Oops.
Hi Pmheider,
Well, you're partly right. If you close the script and open it again you will see the U+000A converted to a newline (in the script). And if you then press Apply, the script will break. But if you insert the script as is and leave it untouched, it should work.
I'm sorry, but this is the best I can offer at the moment! The issue is noted though.
Regards,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!