• Please note: In an effort to ensure that all of our users feel welcome on our forums, we’ve updated our forum rules. You can review the updated rules here: http://forums.wolflair.com/showthread.php?t=5528.

    If a fellow Community member is not following the forum rules, please report the post by clicking the Report button (the red yield sign on the left) located on every post. This will notify the moderators directly. If you have any questions about these new rules, please contact support@wolflair.com.

    - The Lone Wolf Development Team

Scripting Help? If option A exists, remove option B

Mettius

Well-known member
For a given unit, I'm trying to write a script to check if a given option has been selected, and if so, uncheck another option and disable the option so the user cannot select it (unless Option A is unselected)

Also, would I do that in a postlink script, or is there a better place?

Code:
~ If bike is selected, loose Move through cover
if (option[gnKT_Bike].selection > 0) then
   option[gn6_MTC].selection = 0
   option[gn6_MTC].enablement = 0
endif
The code above doesn't work. I get an error at compile time
Code:
Army Builder was forced to stop compilation after the following errors were detected:

Syntax error in 'postlinks' script for unit 'ba3_SSgt' on line 10
  -> Attempt to assign value to read-only identifier
'postlinks' script for unit 'ba3_SSgt' performs selection on invalid option (or chain)
Line 10 is the .selection line.
 
Last edited:
Much like the solution to another question asked recently, I would recommend making the 2 options part of an exclusion group capped at 1. This should then not allow them to select the other option to begin with. This also won't uncheck the option, but it will flag an error until they do (I mention this because there are ways to cause this situation to happen).
 
Also, if an exclusion group doesn't do it for you, you could have the first option add a specific tag to the unit and have the second option only be valid if that tag is not present. This would fulfill your legality requirements as well (but again would not force an uncheck).
 
Yes, exclusion groups are definitely the way to go here, as AntaresCD says. They'll handle the automatic selection / deselection of the "default" option nicely. :)
 
Back
Top