Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Correct way to set boolean experimental variables?

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 True and False in OpenSesame. (And changing this is tricky because of backwards compatibility.) Since all non-empty strings evaluate to True in 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

  • Alright, thank you.

  • Ouch, I just got bit by this too. Thanks for the explanation Sebastiaan.

    Greg Reese

Sign In or Register to comment.