I made a variant of ShowMenu that works with objects:
outputsection = StartNewOutputSection()
msg (caption)
count = 0
game.menuoptionskeys = NewStringList()
foreach (option, options) {
list add (game.menuoptionskeys, option)
count = count + 1
target = ObjectDictionaryItem(options, option)
optionText = target.alias
if (target.cover) {
OutputTextNoBr (count + ": <a class=\"cmdlink\" style=\"" + GetCurrentLinkTextFormat() + "\" onclick=\"ASLEvent('ShowMenuResponse','" + option + "')\">" + optionText + "</a>")
SetForegroundColour ("Red")
msg (" (behind cover)")
SetForegroundColour ("Black")
}
else if (target.defend) {
OutputTextNoBr (count + ": <a class=\"cmdlink\" style=\"" + GetCurrentLinkTextFormat() + "\" onclick=\"ASLEvent('ShowMenuResponse','" + option + "')\">" + optionText + "</a>")
SetForegroundColour ("Red")
msg (" (defending)")
SetForegroundColour ("Black")
}
else {
OutputTextNoBr (count + ": <a class=\"cmdlink\" style=\"" + GetCurrentLinkTextFormat() + "\" onclick=\"ASLEvent('ShowMenuResponse','" + option + "')\">" + optionText + "</a>")
}
}
EndOutputSection (outputsection)
game.menuoptions = options
game.menuallowcancel = allowCancel
game.menucallback = callback
game.menuoutputsection = outputsection
As you can see, it has also been adapted to add text next to an option when it is behind cover or defending. When it tests the flags for these states (if (target.cover)) it appears to find the correct state (if I make the
cover boolean true, it prints "(behind cover)" next to the option; if I make the
defend boolean true, it also responds correctly), however, just after printing the output correctly, it gives me an error message saying that it's trying to read target.cover as an object, and that it can't read it like a boolean. (Error running script: Error compiling expression 'target.cover': RootExpressionElement: Cannot convert type 'Object' to expression result of 'Boolean)
I'm confused, because clearly it's processing the boolean statements--all the way to their conclusion, as I can make every case possible print correctly. But after it finished processing the statements, it doubles back and says, "Oh wait, I can't do that, target.cover is an object." I'm not sure how to proceed in this situation. I appear to be right and wrong at the same time.
As a side note: I'd like to avoid posting my code file at the moment, but if this merits further investigation, I can do that.