Issue with creating a library: tab not showing when using "<onlydisplayif>xxx or yyy</onlydisplayif>"

Banjo
02 May 2018, 09:51

(EDIT: Corrected code formatting)

Hi everyone!

I'm new to Quest so might be missing something obvious, but I've been creating my own "Survival Game" library (with the plan to share it here once it's done) and it's almost done... except I've hit one snag:

I'm using Tabs to make my features GUI friendly, which means showing and hiding some depending on what features are activated (true). However, I can't get this to work properly when using "or" between two attributes in a tab's "onlydisplayif" property.

For example:

   <tab>
    <parent>_GameEditor</parent>
    <caption>Needs</caption>
    <onlydisplayif>game.showhunger or game.showthirst</onlydisplayif>

... doesn't work as expected. I thought that if showthirst OR showhunger was "true", the tab would be shown. However it seems only the first attribute before the "or" is recognised ("showhunger" in this example). If I swap showthirst and showhunger, then "showthirst" is only able to show or hide the tab.

BUT here's the thing:

WORKS:
Set showhunger true, the tab appears...
Set showhunger to false, the tab is hidden...
Set showthirst to true... and the tab is shown (even though showhunger is false)
This is expected behavior, right?

Then why does:
Set showthirst true... tab isn't shown!
Set showhunger to true, the tab is shown!

Shouldn't the "or" in my "onlydisplayif" example mean that either showhunger or showthirst will display the tab??

It's like it needs showhunger to be toggled on and off once before it recognises showthirst.

I feel I've navigated a lot of new stuff learning to make a functioning library, but this one issue really has me stumped, and I'm convinced it's either a program bug or something very simple I've missed doing!

EDIT:
Sorry, after all that, I tried:

  <tab>
    <parent>_GameEditor</parent>
    <caption>Needs</caption>
    <onlydisplayif>(GetBoolean(game, "showhunger") or GetBoolean(game, "showthirst"))</onlydisplayif>

...and that works!

Though I'm still confused why the original code didn't work and that one does, especially since my other "onlydisplayif" with single attributes don't seem to need GetBoolean calls...?


mrangel
02 May 2018, 13:42

Until the attribute has been toggled once, it's unset/null rather than false.
GetBoolean makes it work because it converts null to false.

A truth table:

  • true or truetrue
  • true or falsetrue (while the first two options are both true, the programmer could optimise or, making it return true as soon as it sees a true value. So it doesn't need to look at the second attribute)
  • true or nulltrue (Because of the optimisation mentioned above, it never looks at the second value, so no error)
  • false or truetrue
  • false or falsefalse
  • false or null → error (treated as false by <onlydisplayif>)
  • null or null → error (treated as false by <onlydisplayif>)
  • null or true → error (treated as false by <onlydisplayif>) - this is the only one where you'd expect the tab to display but it doesn't
  • null or false → error (treated as false by <onlydisplayif>)

especially since my other "onlydisplayif" with single attributes don't seem to need GetBoolean calls...?

With single attributes, it doesn't display the tab until the attribute has been set. But that's what you expect.


Banjo
02 May 2018, 15:56

Thanks so much! That makes sense and helped clear it up for me. I appreciate it.

And yes, that "null or true" was the one I was suspecting but couldn't figure out why it wasn't showing the tab! :)

Out of curiosity, is it better practice for me to keep using GetBoolean (which works) for this then, or should I be setting all those attributes to defaults so they aren't "null" before checking for a tab?

(aside from this puzzlement, it's been quite fun figuring out how to make a library for Quest!)