State checklist dialogue

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
qcgreywolf
Cave Troll
Posts: 43
Joined: Mon Dec 09, 2013 10:23 pm

State checklist dialogue

Post by qcgreywolf »

Gentlemen,

Thanks for the help in the past. I have another, probably quick, question.

I would like a popup dialogue that lists all the states and how they are currently set, in check box format. Bonus points if we can get them in 2 columns.
(I figure later I can use deleteStrProp or listDelete to remove out the ones I do not care about, before parsing them)

I currently have a macro that does just that, but it is A LOT of lines of code. I got the idea in my head to really boil it down to an easy core of code, but I do not know how to get it into the dialogue input...

Very brief example of what I have now (incomplete example)

Code: Select all

[h: statusBlind = getState("Blind")]
[h: statusConfused = getState("Confused")]
[h: statusDazed = getState("Dazed")]
[h: statusDazzled = getState("Dazzled")]
[h: statusDeafened = getState("Deafened")]
[h: statusDisabled = getState("Disabled")]
[h: statusDying = getState("Dying")]
[h: statusEntangled = getState("Entangled")]
[h: statusExhausted = getState("Exhausted")]
[h: statusFatigued = getState("Fatigued")]
[h: statusGrappled = getState("Grappled")]
[h: statusInvisible = getState("Invisible")]
[h: statusNauseated = getState("Nauseated")]
[h: statusParalyzed = getState("Paralyzed")]
[h: statusProne = getState("Prone")]
[h: statusShaken = getState("Shaken")]
[h: statusSickened = getState("Sickened")]
[h: statusStaggered = getState("Staggered")]
[h: statusStunned = getState("Stunned")]
[h: statusUnconscious = getState("Unconscious")]

[h: abort(input(
   strformat("statusBlind|%{statusBlind}|Blind|CHECK|"),
   strformat("statusConfused|%{statusConfused}|Confused|CHECK|"),
   strformat("statusDazed|%{statusDazed}|Dazed|CHECK|"),
   strformat("statusDazzled|%{statusDazzled}|Dazzled|CHECK|"),
   strformat("statusDeafened|%{statusDeafened}|Deafened|CHECK|"),
   strformat("statusDisabled|%{statusDisabled}|Disabled|CHECK|")
))] 
I have been playing with this code, right out of the wiki:dialogue input. I think you guys should be able to see what I 'want' to do

Ignore everything from the wiki example except for the <!-- Build input form advanced --> section. That's what I want to work. (the example is mostly unchanged, because everything I have tried won't work properly. I just input junk variables topically so you understand the intent)

(Edited, removed non-essential code, to make clear the question and intent)

Code: Select all

<!-- Delete me -->
[h: resetAllStates = 0]

[h: listPile = ""]

[h: statesPile = getTokenStates()]

[h, FOREACH(current, statesPile), CODE:
    {
	[h: stateOutput = 0]
	[h: stateOutput = getState(current)]
	[h: listPile = listAppend(listPile, current)]
	[h: listPile = listAppend(listPile, stateOutput)]
    }
]
 
<!-- Build input form advanced -->
[H: inputStr = json.append(inputStr,"junk|<html><b>A complex example</b></html>|-|LABEL|SPAN=TRUE")]
[H, foreach(stat,listPile): inputStr = json.append(inputStr,   strformat("state|%{state}|status|CHECK|"),"))]
 
<!-- put local variables in input form -->
[H: inputStr = json.evaluate(inputStr)]
 
<!-- get user input -->
[H: hasInput = input(json.toList(inputStr,"##"))]

Any hints on how to proceed?

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

Re: State checklist dialogue

Post by metatheurgist »

Code: Select all

[h:tokenstates=getTokenStates()]

[h:input=""]
[h,foreach(state,tokenstates): input=listAppend(input,"state"+state+"|"+getState(state)+"|"+state+"|CHECK","##")]

[h:status=input(
  input
)]
[h:abort(status)]

[r:stateDead]
You can't get multiple columns with an input(). To get better presentation you'll have to use a dialog.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: State checklist dialogue

Post by wolph42 »

I (re)wrote a html form that shows all states on a token as checkboxes including images and their group. I can't remember the original author, but the code is reasonably copy-pastable. You can find it in my W40k framework (link in sig.)

edit: slight update of above code:

Code: Select all

[h:tokenstates    = getTokenStates()]
[h:inputStr        = ""]
[h,foreach(state,tokenstates): inputStr    = listAppend(inputStr,"state"+state+"|"+getState(state)+"|"+state+"|CHECK","##")]
[h:abort(input(inputStr))] 

qcgreywolf
Cave Troll
Posts: 43
Joined: Mon Dec 09, 2013 10:23 pm

Re: State checklist dialogue

Post by qcgreywolf »

Thanks gentlemen, that does help out. That solved 2/3 of the problem I was having... That should shorten up my code in that macro by many dozens of lines of code. Thanks!

I have managed a lot of neat feats by myself over the last year or so, and it is fun(read: also frustrating) to go back with my new found knowledge and making code more elegant and efficient.

Post Reply

Return to “Macros”