menu with variable options

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
paulstrait
Dragon
Posts: 302
Joined: Mon Mar 23, 2009 4:48 pm

menu with variable options

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

User avatar
metatheurgist
Dragon
Posts: 350
Joined: Mon Oct 26, 2009 5:51 am

Re: menu with variable options

Post 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]

paulstrait
Dragon
Posts: 302
Joined: Mon Mar 23, 2009 4:48 pm

Re: menu with variable options

Post by paulstrait »

Thanks!

Post Reply

Return to “Macros”