• 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

How to use setchosen[]?

ploturo

Well-known member
Does anyone know how to use the setchosen[...] target reference on a menu field?

For example
Code:
<field id="someField" name="Example" type="user" style="menu"/>

...

perform field[someField].setchosen[Component,...?]

I've been able to figure out that the first parameter expects the id of a defined component, and there is at least a second parameter. But so far I've just gotten as far an "Invalid setchosen syntax used" error during compile, and not even any of the potential runtime errors.


Being able to set the value of menu-style user fields would make one thing possible that I haven't found any other solution for (creating a shadowed proxy pick to use with a menu_thing in the UI, and pass on the result to an already existing non-shadowed pick).

It would also help me to clean up some messy scripts/workarounds I've written, since I would be able to use a menu-style field as a simple script-modified linkage.
 
I was able to track down an example in a procedure (xactMonSet from pathfinder).

Code:
~if we need to select from the list of factions, provide an initial
~selection of the first one that has non-zero prestige to spend
if (empty(hero.transact.field[xactFixFac].text) <> 0) then
     var factexpr as string
     factexpr = "(" & hero.transact.field[xactFacLis].text & ") & (fieldval:facCPA > 0)"
     if (hero.haschild[BaseFact,factexpr] <> 0) then
          perform hero.transact.field[xactFact].setchosen[BaseFact,factexpr,hero]
          endif
     endif

One thing to note is that the script has to be trusted to be able to change any user field (which all menu-style fields are), otherwise you will sometimes get strange compilation errors. Certain types of scripts are trusted by default (like creation scripts), and otherwise you will need to use a trustme statement.
 
setchosen could very easily overwrite the user's choices in drop-downs, so it definitely needs to be in a trusted script - using setchosen is a sledgehammer approach, and I don't think I've ever used it except in a creation script, to set a default the user can later change. For most cases where you need to choose a specific thing for the user, assigning an identity tag that says "the thing with this Id was chosen for this menu" and then writing your scripts to first check for that tag, then check if the user made a choice is the better solution for cases like "You gain X as a bonus, but it must choose Y".
 
Back
Top