Lone Wolf Development Forums

Lone Wolf Development Forums (http://forums.wolflair.com/index.php)
-   HL - Authoring Kit (http://forums.wolflair.com/forumdisplay.php?f=58)
-   -   How to use setchosen[]? (http://forums.wolflair.com/showthread.php?t=66812)

ploturo February 19th, 2022 05:27 PM

How to use setchosen[]?
 
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.

ploturo February 25th, 2022 03:04 PM

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.

Mathias February 25th, 2022 05:10 PM

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".


All times are GMT -8. The time now is 12:34 PM.

Powered by vBulletin® - Copyright ©2000 - 2024, vBulletin Solutions, Inc.
wolflair.com copyright ©1998-2016 Lone Wolf Development, Inc. View our Privacy Policy here.