Page 1 of 1

menu with variable options

Posted: Wed Sep 11, 2019 9:33 pm
by paulstrait
I'm trying to program a macro for the Crimson Rite ability of the Blood Hunter class. Depending on one's level and choices, the character could have one, two, or three options. I would like for the macro to provide a drop down menu that lists only the options that the character has. I'm storing the options in a variable called PrimalRite that looks like this:

Code: Select all

{"Flame":1,"Frozen":0,"Storm":1}
In the above case, the character would have access to the Flame and Storm, but not Frozen options. Is there a way to set up a menu in my Crimson Rite macro that would be able to provide a menu that only includes options with a value of 1?

I could just create 7 menus (one for each possible case), but I suspect there is a better way.

Re: menu with variable options

Posted: Fri Sep 13, 2019 6:56 am
by metatheurgist

Code: Select all

[h:jPowers='{"Flame":1,"Frozen":0,"Storm":1}']

[h:sPowers=json.fields(jPowers)]
[h:sChoices=""]
[h,foreach(sPower,sPowers), code:
{
  [if(json.get(jPowers,sPower)==1): sChoices=listAppend(sChoices,sPower)]
}]

[h:status=input(
  "sSelected|"+sChoices+"|Select|LIST|SELECT=0 VALUE=STRING",
  "iSelected|"+sChoices+"|Select|RADIO|SELECT=0"
)]
[h:abort(status)]

List: [r:sSelected]<br>
Radio:[r:iSelected]

Re: menu with variable options

Posted: Mon Sep 16, 2019 10:48 pm
by paulstrait
Thanks!