Flags and replacing items in a list

I would like to add attributes to a flag (eg colours) based on some criteria (if). I figured that flags are lists, but I cannot figure out how to replace an item on a list.

For example this code:
if {$priority="Must-have"}{$Flags="orange"} if {$Target_platform.contains("OPUS")}{$Flags=$Flags+"-white"} if {$Target_platform.contains("MAGNUM")}{$Flags=$Flags+"-green"}

will just add to the list, while I want to just add to the first string on the $Flags list

The workaround has been to create a temp variable and then replace the $Flags with that, but I’m sure there’s a better way.

if {$priority="must-have"}{$temp="orange"} if {$Target_platform.contains("OPUS")}{$temp=$temp+"-blue"} if {$Target_platform.contains("MAGNUM")}{$temp=$temp+"-green"} $Flags=$temp

I couldn’t find in aTbRef (I’m sure it’s in there somewhere) information on how to manipulate lists.

Lists are described here. Lists hold their order (good for this scenario) but adding to a list generally means adding to the of the list (not so helpful). You might think to try this:

$Flags = "orange" ; // a 1 item list
$Flags = "blue" + $Flags; // 1 item but value "blueorange"

Why. Well we’re taking a string ‘blue’ and adding textual data to it (even if the latter is a list). So Tinderbox figures, I’m adding to a string, not pre-pending to a list!

So, we need to tell the Tinderbox parser that the new item #1 is itself a (single-value) List. That involves the newer [] list declaration method . So:

$Flags = [blue] + $Flags;

Note, using the [] method quotes are not needed (the square braces signal purpose/type).

Thus your code becomes:

if {$priority="Must-have"}{$Flags="orange"};
if {$Target_platform.contains("OPUS")}{$Flags=[white]+$Flags};
if {$Target_platform.contains("MAGNUM")}{$Flags=[green]+$Flags};

†. I just added info on using the [] method in this context onto the aTbRef page on List-type (link above).

‡. Indeed, from v9.6.0—due imminently—the [ ] list declaration supersedes the older method of simply putting quotes around a semi-coon limited list. Both continue to work, but the [ ] methods is less ambiguous to the parser as to the type of info being added. Indeed, in the above scenario it is the only method of the two that works.

1 Like

$Flags is a list, because a note might fly several flags. This action, for example, gives its note two flags:


If we want to change the first flag of a note to a different flag, we might write: