State macro selection with check boxes instead of drop down menu?

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

User avatar
Oryan77
Dragon
Posts: 452
Joined: Sun Feb 20, 2011 3:14 pm

Re: State macro selection with check boxes instead of drop down menu?

Post by Oryan77 »

metatheurgist wrote:
Mon Dec 17, 2018 8:34 pm

Though it may be easier just to replace the getTokenStates() call with

[sStates="Astral Form, Blinded, Bloodied, Burning, Concentration, Confused, Cowering,
Critical Damage, Dazed, Dazzled, Dead, Deafened, Dehydration, Disabled, Diseased,
Diseased (unaware), Drowning, Dying, Entangled, Ethereal Form, Exhausted,
Fascinated, Fatigued, Frightened, Grappled, Helpless, Nauseated, Negative Level,
Panicked, Paralyzed, Petrified, Poisoned, Poisoned (unaware), Prone, Shaken,
Sickened, StableHP, Staggered, Starvation, Stunned, Suffocation, Surprised, Unconscious"]

Since that is the list of states you had in your original code.
That did it. Thank you very much!

User avatar
Oryan77
Dragon
Posts: 452
Joined: Sun Feb 20, 2011 3:14 pm

Re: State macro selection with check boxes instead of drop down menu?

Post by Oryan77 »

This worked out great and I included a screenshot of what I came up with below.

I used the state name list to pull each of these states like you last suggested. Is there a way to adjust that if I want to rename the text belonging to the state in the window without renaming the state name?

For example, you will see that the Stable state is listed as "StableHP" because that is the name of the state, but I would like it displayed as "Stable". Other states that I plan to use do not use apostrophes in the actual state name, but it would be nice for the name to include the apostrophe when it appears in this window (like Bulls Strength to Bull's Strength).
States Macro.jpg
States Macro.jpg (379.79 KiB) Viewed 567 times

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: State macro selection with check boxes instead of drop down menu?

Post by aliasmask »

You would need 2 lists. One list is the state name and the 2nd list is the name you wish displayed. Not sure which loop you use, but if using a foreach you can get the position with roll.count to get display name.

Code: Select all

[H: stateNames = "state1,state2,state3"]
[H: displayNames = "Dead,Dying,Unconscious"]
[H, foreach(name,stateNames), code: {
   [H: stateImage = getStateImage(name)]
   [H: stateName = listGet(displayNames,roll.count)]
   ...
}]

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

Re: State macro selection with check boxes instead of drop down menu?

Post by metatheurgist »

I see some of my dodgy artwork has invaded another framework. :mrgreen:

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: State macro selection with check boxes instead of drop down menu?

Post by aliasmask »

I'm working on something where I'm going to redo the states icons using this site: https://game-icons.net/

Very nice resource. For example, an icon for a small button:
Attachments
Token TWF.png
Token TWF.png (14.64 KiB) Viewed 562 times

User avatar
Oryan77
Dragon
Posts: 452
Joined: Sun Feb 20, 2011 3:14 pm

Re: State macro selection with check boxes instead of drop down menu?

Post by Oryan77 »

metatheurgist wrote:
Wed Dec 19, 2018 5:29 am
I see some of my dodgy artwork has invaded another framework. :mrgreen:
Yes, I used a couple of your images since I was not currently using conditions for those. Nice!

User avatar
Oryan77
Dragon
Posts: 452
Joined: Sun Feb 20, 2011 3:14 pm

Re: State macro selection with check boxes instead of drop down menu?

Post by Oryan77 »

I inserted the new code but I'm apparently not doing it correctly because I can't get "Stable" to appear in the window. Here is what I did:
Spoiler

Code: Select all

[abort(isGM())]

[sStates="Astral Form, Blinded, Bloodied, Burning, Concentration, Confused, Cowering,
Critical Damage, Dazed, Dazzled, Dead, Deafened, Dehydration, Delaying Action, Disabled, Diseased,
Diseased (unaware), Drowning, Dying, Encumbered, Entangled, Ethereal Form, Exhausted,
Fascinated, Fatigued, Fighting Defensively, Frightened, Grappled, Helpless, Nauseated, Negative Level,
Overloaded, Panicked, Paralyzed, Petrified, Poisoned, Poisoned (unaware), Prone, Readied Action, Shaken,
Sickened, Staggered, Starvation, Stunned, Suffocation, Surprised, Total Defense, Unconscious"]

[H: stateNames = "StableHP"]
[H: displayNames = "Stable"]
[H, foreach(name,stateNames), code: {
   [H: stateImage = getStateImage(name)]
   [H: stateName = listGet(displayNames,roll.count)]
}]

[dialog("States","width=508; height=620; temporary=0; input=1; noframe=0"):
{
<html>
<body>
[h: sProcessorlink = macroLinkText("ProcessState@lib:States", "all","","selected")]
<form action="[r:sProcessorlink]" method="json">
<table cellpadding=4>

[h:iCount=0]

[foreach(sState,sStates,"<br>"), code:
{
  [h:iQuotient=Floor(iCount/4)]
  [h:iRemainder=(iCount/4)-iQuotient)*4]
  [r,if(iRemainder==0): sOut="<tr>"]
  [h:sStateimage=getStateImage(sState)]
  <td>
  <table cellpadding=0>
  <tr><td><input type="checkbox"  name="[r:sState]" [r,if(getState(sState)): sOut="checked"]></td>
 <td colspan=2><img src="[r:sStateimage]" width=35 height=35></td>
         <td>[r:sState]</td></tr>

  </table>
  </td>

  [r,if(iRemainder==4): sOut="</tr>"]
  [h:iCount=iCount+1]
}]

</table>
<br>
<center><input type="submit" value="Okay"></center>
</form>
</body>
</html>
}]
[H: abort(0)]
Last edited by Oryan77 on Wed Dec 19, 2018 12:55 pm, edited 1 time in total.

User avatar
Oryan77
Dragon
Posts: 452
Joined: Sun Feb 20, 2011 3:14 pm

Re: State macro selection with check boxes instead of drop down menu?

Post by Oryan77 »

Also, I just realized that if I am using a state on the token that does not appear in this macro, this macro removes the state and only uses the states that were selected via this macro. How can I tweak this?

ProcessState macro
Spoiler

Code: Select all

[abort(isGM())]
[h:jStates=macro.args]
[h:cHiddenstates=json.set("{}","Hide",1,"Hide from Animals",1,"Hide from Undead",1,"Invisibility",1,"Invisibility Greater",1)]
[h:cHelplessstates=json.set("{}","Prone",1,"Unconscious",1)]


[h:sStates=json.fields(jStates)]
[h,if(listContains(sStates,"Fatigued") && listContains(sStates,"Exhausted")): sStates=listDelete(sStates,listFind(sStates,"Fatigued"))]




[h: SelectedTokens=getSelected()]
[FOREACH(TokenID, SelectedTokens, " "), CODE:
  {
   [h: NewState=if(getState("Hide",TokenID)==1,0,1)]
   [h: setState("Hide",NewState,TokenID)]
   [h: NewVisible=if(getVisible(TokenID)==1,0,1)]
   [h: NewState=if(getState("Hide from Animals",TokenID)==1,0,1)]
   [h: setState("Hide from Animals",NewState,TokenID)]
   [h: NewState=if(getState("Hide from Undead",TokenID)==1,0,1)]
   [h: setState("Hide from Undead",NewState,TokenID)]
   [h: NewState=if(getState("Invisibility",TokenID)==1,0,1)]
   [h: NewState=if(getState("Invisibility Greater",TokenID)==1,0,1)]
   [h: setState("Invisibility Greater",NewState,TokenID)]
   [h: setState("Invisibility",NewState,TokenID)]
   [h: NewHidden=if(getVisible(TokenID)==1,1,0)]
   [h: setVisible(NewVisible,TokenID)]
   [h: setState("Hidden",NewHidden,TokenID)]
}]


[h:jHidden=json.intersection(jStates,cHiddenstates)]
[h:jHelpless=json.intersection(jStates,cHelplessstates)]


[h,if(json.length(jHidden)): sStates=listAppend(sStates,"Hidden")]
[h,if(json.length(jHelpless)): sStates=listAppend(sStates,"Helpless")]


[h:setAllStates(0)]

[h,foreach(sState,sStates,""), code:
{
  [setState(sState,1)]
}]

[H: abort(0)]
State macro
Spoiler

Code: Select all

[abort(isGM())]

[H: sStates ="Astral Form, Blinded, Bloodied, Burning, Concentration, Confused, Cowering,
Critical Damage, Dazed, Dazzled, Dead, Deafened, Dehydration, Delaying Action, Disabled, Diseased,
Diseased (unaware), Drowning, Dying, Encumbered, Entangled, Ethereal Form, Exhausted,
Fascinated, Fatigued, Fighting Defensively, Frightened, Grappled, Helpless, Nauseated, Negative Level,
Overloaded, Panicked, Paralyzed, Petrified, Poisoned, Poisoned (unaware), Prone, Readied Action, Shaken,
Sickened, StableHP, Staggered, Starvation, Stunned, Suffocation, Surprised, Total Defense, Unconscious"]

[H: displayNames ="Astral Form, Blinded, Bloodied, Burning, Concentration, Confused, Cowering,
Critical Damage, Dazed, Dazzled, Dead, Deafened, Dehydration, Delaying Action, Disabled, Diseased,
Diseased (unaware), Drowning, Dying, Encumbered, Entangled, Ethereal Form, Exhausted,
Fascinated, Fatigued, Fighting Defensively, Frightened, Grappled, Helpless, Nauseated, Negative Level,
Overloaded, Panicked, Paralyzed, Petrified, Poisoned, Poisoned (unaware), Prone, Readied Action, Shaken,
Sickened, Stable, Staggered, Starvation, Stunned, Suffocation, Surprised, Total Defense, Unconscious"]

[dialog("States","width=508; height=620; temporary=0; input=1; noframe=0"):
{
<html>
<body>
[h: sProcessorlink = macroLinkText("ProcessState@lib:States", "all","","selected")]
<form action="[r:sProcessorlink]" method="json">
<table cellpadding=4>

[h:iCount=0]

[foreach(sState,sStates,"<br>"), code:
{
  [h:iQuotient=Floor(iCount/4)]
  [h:iRemainder=(iCount/4)-iQuotient)*4]
  [r,if(iRemainder==0): sOut="<tr>"]
  [h:sStateimage=getStateImage(sState)]
  [H: stateName = listGet(displayNames,iCount)]
  <td>
  <table cellpadding=0>
  <tr><td><input type="checkbox"  name="[r:sState]" [r,if(getState(sState)): sOut="checked"]></td>
 <td colspan=2><img src="[r:sStateimage]" width=35 height=35></td>
         <td>[r:stateName]</td></tr>

  </table>
  </td>

  [r,if(iRemainder==4): sOut="</tr>"]
  [h:iCount=iCount+1]
}]

</table>
<br>
<center><input type="submit" value="Okay"></center>
</form>
</body>
</html>
}]
[H: abort(0)]
Last edited by Oryan77 on Wed Dec 19, 2018 5:07 pm, edited 1 time in total.

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: State macro selection with check boxes instead of drop down menu?

Post by aliasmask »

Code: Select all

@@ @stateMacro
[abort(isGM())]

[H: sStates ="Astral Form, Blinded, Bloodied, Burning, Concentration, Confused, Cowering,
Critical Damage, Dazed, Dazzled, Dead, Deafened, Dehydration, Delaying Action, Disabled, Diseased,
Diseased (unaware), Drowning, Dying, Encumbered, Entangled, Ethereal Form, Exhausted,
Fascinated, Fatigued, Fighting Defensively, Frightened, Grappled, Helpless, Nauseated, Negative Level,
Overloaded, Panicked, Paralyzed, Petrified, Poisoned, Poisoned (unaware), Prone, Readied Action, Shaken,
Sickened, StableHP, Staggered, Starvation, Stunned, Suffocation, Surprised, Total Defense, Unconscious"]

[H: displayNames ="Astral Form, Blinded, Bloodied, Burning, Concentration, Confused, Cowering,
Critical Damage, Dazed, Dazzled, Dead, Deafened, Dehydration, Delaying Action, Disabled, Diseased,
Diseased (unaware), Drowning, Dying, Encumbered, Entangled, Ethereal Form, Exhausted,
Fascinated, Fatigued, Fighting Defensively, Frightened, Grappled, Helpless, Nauseated, Negative Level,
Overloaded, Panicked, Paralyzed, Petrified, Poisoned, Poisoned (unaware), Prone, Readied Action, Shaken,
Sickened, Stable, Staggered, Starvation, Stunned, Suffocation, Surprised, Total Defense, Unconscious"]

[dialog("States","width=508; height=620; temporary=0; input=1; noframe=0"):
{
<html>
<body>
[h: sProcessorlink = macroLinkText("ProcessState@lib:States", "all","","selected")]
<form action="[r:sProcessorlink]" method="json">
<table cellpadding=4>

[h:iCount=0]

[foreach(sState,sStates,"<br>"), code:
{
  [h:iQuotient=Floor(iCount/4)]
  [h:iRemainder=(iCount/4)-iQuotient)*4]
  [r,if(iRemainder==0): sOut="<tr>"]
  [h:sStateimage=getStateImage(sState)]
  [H: stateName = listGet(displayNames,iCount)]
  <td>
  <table cellpadding=0>
  <tr><td><input type="checkbox"  name="[r:sState]" [r,if(getState(sState)): sOut="checked"]></td>
 <td colspan=2><img src="[r:sStateimage]" width=35 height=35></td>
         <td>[r:stateName]</td></tr>

  </table>
  </td>

  [r,if(iRemainder==4): sOut="</tr>"]
  [h:iCount=iCount+1]
}]

</table>
<br>
<center><input type="submit" value="Okay"></center>
</form>
</body>
</html>
}]
[H: abort(0)]

!!

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

Re: State macro selection with check boxes instead of drop down menu?

Post by metatheurgist »

Oryan77 wrote:
Wed Dec 19, 2018 12:54 pm
Also, I just realized that if I am using a state on the token that does not appear in this macro, this macro removes the state and only uses the states that were selected via this macro. How can I tweak this?
You need to make a list of the states that aren't in the dialog, record which ones are on.

[sHiddenStates="{list of hidden states}"]
[sHiddenStatesActive=""]
[foreach(sState,sHiddenStates,""), code:
{
[bState=getState(sState)]
[if(bState): sHiddenStatesActive=listAppend(sHiddenStatesActive,sState)]
}]

Then add that to the list of states selected by the dialog.

[sStates=listAppend(sStates,sHiddenStatesActive)]

UNTESTED!

User avatar
Oryan77
Dragon
Posts: 452
Joined: Sun Feb 20, 2011 3:14 pm

Re: State macro selection with check boxes instead of drop down menu?

Post by Oryan77 »

Is there a more broad way of accomplishing this rather than manually listing out each "hidden" state?

I use elevation and negative level macros which adds a range of numbers (states) to the token along with the corresponding image state. I also use light macros that add states to correspond with the light source. This is around 100 total states that are not included in the above macro.

Many of the states that are not going to be used in this macro are also in the same state group name as the states used in this macro.

Or maybe only look for states listed in the macro and only turn those on/off (ignoring any other states) rather than looking for hidden states?

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

Re: State macro selection with check boxes instead of drop down menu?

Post by metatheurgist »

In ProcessState

[sStatesOff="{list of states in dialog}"]

[jaStatesOn=json.fromList(sStates)]
[jaStatesOff=json.fromList(sOffstates)]
[jaStatesOff=json.difference(jaOffStates,jaOnStates)]
[sStatesOff=json.toList(jaStatesOff)]

remove the SetAllStates(0)

[h,foreach(sState,sStatesOff,""), code:
{
[setState(sState,0)]
}]

Again UNTESTED.

User avatar
Oryan77
Dragon
Posts: 452
Joined: Sun Feb 20, 2011 3:14 pm

Re: State macro selection with check boxes instead of drop down menu?

Post by Oryan77 »

I get the following errors:

Value For sOffstates

Value For jaOffStates

Value For jaOnStates

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

Re: State macro selection with check boxes instead of drop down menu?

Post by metatheurgist »

Typos. Which is what happens you change your mind about variable naming scheme in the middle of coding.

[jaStatesOn=json.fromList(sStates)]
[jaStatesOff=json.fromList(sStatesOff)]
[jaStatesOff=json.difference(jaStatesOff,jaStatesOn)]
[sStatesOff=json.toList(jaStatesOff)]

User avatar
Oryan77
Dragon
Posts: 452
Joined: Sun Feb 20, 2011 3:14 pm

Re: State macro selection with check boxes instead of drop down menu?

Post by Oryan77 »

I'm not sure if I am following your instructions incorrectly, or placing the new code in the wrong section, or if there is still an error in your code; but I still get some errors regardless what I do. Would you mind correcting my macro with your changes just so I know that I have the correct format and can better relay information if there is still an issue?

Here is my code so far:
Spoiler

Code: Select all

[abort(isGM())]
[h:jStates=macro.args]
[h:cHiddenstates=json.set("{}","Ethereal Form",1,"Hide",1,"Hide from Animals",1,"Hide from Undead",1,"Invisibility",1,"Invisibility Greater",1)]
[h:cPronestates=json.set("{}","Unconscious",1,"Sleep",1)]
[h:cInvisibilitystates=json.set("{}","Ethereal Form",1)]
[h:cHiddenstates=json.set("{}","Ethereal Form",1,"Hide",1,"Hide from Animals",1,"Hide from Undead",1,"Invisibility",1,"Invisibility Greater",1)]

[h:sStates=json.fields(jStates)]
[h,if(listContains(sStates,"Fatigued") && listContains(sStates,"Exhausted")): sStates=listDelete(sStates,listFind(sStates,"Fatigued"))]


[h:jHidden=json.intersection(jStates,cHiddenstates)]
[h:jProne=json.intersection(jStates,cPronestates)]
[h:jInvisibility=json.intersection(jStates,cInvisibilitystates)]


[h,if(json.length(jHidden)): sStates=listAppend(sStates,"Hidden")]
[h,if(json.length(jProne)): sStates=listAppend(sStates,"Prone")]
[h,if(json.length(jInvisibility)): sStates=listAppend(sStates,"Invisibility")]

[h: SelectedTokens=getSelected()]
[FOREACH(TokenID, SelectedTokens, " "), CODE:
  {
[h,if(json.length(jHidden)): NewVisible=if(getVisible(TokenID)==1,0,1)]
[h,if(json.length(jHidden)): NewHidden=if(getVisible(TokenID)==1,1,0)]
[h,if(json.length(jHidden)): setVisible(NewVisible,TokenID)]
[h,if(json.length(jHidden)): setState("Hidden",NewHidden,TokenID)]
}]


[h:setAllStates(0)]

[h,foreach(sState,sStates,""), code:
{
  [setState(sState,1)]
}]


[H: abort(0)]

Post Reply

Return to “Macros”