Operation 'Equal' is not defined for types 'Object' and 'Boolean'

Why Equal works with a boolean when using the if text comand but it's not working when using the script function if?

This works: {if piano.b = True: [B]}
This doesn't work: if (piano.b=True)

Because the text processor internally calls GetBoolean, which returns false if an attribute is not defined. When you reference an attribute directly, it must be defined. You can do the same:

if (GetBoolean(piano, "b")=True)


though I would just do:

if (GetBoolean(piano, "b"))