Correct way to set boolean experimental variables?
in OpenSesame
Hi,
I have tried to use
exp.set("myBoolean",True)
to set (and create) boolean variables in inline scripts, but the variable inspector shows, that this sets the variable to 'yes' (or 'no' in case of false). If I try to use this variable later in the form
if(var.myBoolean):
the if clause is always true (even if myBoolean is 'no').
An easy workaround of course is to use integers and set the variable to 0 or 1 or to use strings. But is there a correct way to set boolean variables to get the correct behaviour?
Comments
Hi Leo,
This is a good point, and it results from the (poor) decision long ago to use the strings 'yes' and 'no' for
TrueandFalsein OpenSesame. (And changing this is tricky because of backwards compatibility.) Since all non-empty strings evaluate toTruein Python, you get the behavior that you're seeing.An easy workaround of course is to use integers and set the variable to 0 or 1
That would be my recommendation.
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Alright, thank you.
Ouch, I just got bit by this too. Thanks for the explanation Sebastiaan.
Greg Reese