FS#12891 - %?if() evaluates enumeration indexes and arbitrary numbers to (number + 1)

Attached to Project: Rockbox
Opened by Guillaume Cocatre-Zilgien (gcocatre) - Thursday, 22 August 2013, 09:35 GMT
Task Type Bugs
Category Themes
Status Unconfirmed
Assigned To No-one
Operating System All players
Severity Low
Priority Normal
Reported Version Release 3.12
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 0
Private No


When displaying %mp in a theme while playback is stopped, the value 0 (zero) is displayed.

However, to test for "playback stopped", one has to test:
%?if(%mp, =, 1)
That is, one has to test for (index + 1) in order to return true for any given enumerator index number.

Same problem when testing for an arbitrary number. Example:
%?if(%ss(0, 2, %St(font), number), =, 15)
returns true when the font is set to "14-Nimbus", and false when the font is set to "15-Adobe-Helvetica".

When testing a %tag that holds a numerical value though, it works as expected:
%?if(%pv, =, 0)
returns true when volume is set to 0dB.

Fixing this would likely break all existing Rockbox themes. One solution to this, would be to require new / updated themes to include some specific code that "acknowledges" the new behavior.
This task depends upon

Comment by Chris Jordan (chrisjj) - Thursday, 09 January 2014, 14:42 GMT
Another possible solution:

Now: Endorse current if() behaviour by documenting it
Soon: Add a ifV2() that works as expected
Then: Declare if() to be deprecated

Comment by Thomas Martitz (kugel.) - Friday, 10 January 2014, 21:04 GMT
The problem is that the value (the one you get via %if) is used for conditionals too. A value of 0 in conditionals selects the false branch, which always the most right one. We do not want this for enumerations, where the first value should be the most left one. For this reason 0 changes to 1, 1 to 2, and so on. I understand that this is inconsistent with the value printed. FWIW, I think few (if any) people print the value of %mp, it's always used as conditional to display bitmaps.

Your second example surprises me a lot, though.