Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Modifying different attributes using ChatSetAttr with a drop down menu

1734016634

Edited 1734018192
I'm trying to make a dropdown menu that prompts the player to choose a selection, which when chosen sets said attribute using ChatSetAttr, the point here being a toggle macro for a special condition. The problem I'm running into is the syntax of the dropdown menu is interfering with chatsetattr syntax.  The current macro is: ?{Are you clean?|Yes, !setattr --name Sunscale --clean|1|No, !setattr --name Sunscale --clean|0} But using the macro gives this into chat and no attribute change: !setattr --name Sunscale --clean I understand WHY this is happening, the pipes are making the macro think that's the end of the syntax for that drop down menu option, which cuts off the chatsetattr syntax and breaks it; the drop down menu is giving options for Clean, 1, Dirty, 2. I've tried: using HTML entities to replace the pipes, which eliminates the 1 and 2 options in the dropdown, but then just posts this to the chat, without chatsetattr doing anything: !setattr --name Sunscale --clean|1 using # instead of a pipe in the chatsetattr syntax, which just outputs something similar into chat. I'm just not sure how to avoid this and make the macro work, or if it's even possible. It seems that there being multiple attempts to call the script in the macro is breaking the functionality maybe. Advice?
1734018663
timmaugh
Pro
API Scripter
I wouldn't solve it in the way I'm about to show -- see below for that. First, I just want to show the issue so that you know for the next time what is happening. You have characters in your ChatSetAttr command that normally act as control characters for the query -- and the Roll20 query parser isn't context-aware enough to know the difference. It only knows to watch for those characters to move to different parts of its parsing logic. To get around that, you have to use HTML replacements on the parts of the ChatSetAttr command line that will interfere with the roll query: These are the query-control characters to watch for: CHAR | TYPE | QUERY CMD ======|==============|========================= | | pipe | move to next query item , | comma | within query item, move to next component (ie, name to value) } | right brace | end query If you want these to not be interpreted by the query parser, you have to use their HTML replacements. Lots of people use their numeric versions (i.e., |), but I prefer the more human-readable versions:   | => |   , => ,   } => } Replacing those characters where they need to be interpreted by ChatSetAttr (rather than the query) would look like: ?{Are you clean?|Yes, !setattr --name Sunscale --clean|1|No, !setattr --name Sunscale --clean|0} That's the lesson of the query control characters... but... What I'd Really Do Normally, you can rewrite your line so that the command contains the query rather than the other way around. That will shorten (and simplify) your line: !setattr --name Sunscale --clean| ?{Are you clean?|Yes,1|No,0} No HTML replacements necessary. But I still have a question I Still Have a Question Your post said that you want to choose from multiple attributes, but your example was dealing with a single attribute and you're choosing whether or not to put a "1" in the value. One interpretation I can see for your post is that you need the player to answer the "Are you clean?" query, and then take different actions on different attributes for that character based on the response (ie, adding 1 here, making a 0 there, etc.). Having to use a single query to represent multiple different effects like this would mean, in standard Roll20 usage, that  you would HAVE TO structure the query the way you initially did -- where the query encloses (at least part of) the ChatSetAttr line. That is, within the "Yes, I am clean" portion of the query response  you would have the value of "1" for Sunscale, the value of "0" for Mudbath, and maybe a +5 for Oi_papi_looking_gooood. DON'T LOOK AT ME LIKE THAT -- I DON'T MAKE UP THE ATTRIBUTES; IT'S YOUR GAME SYSTEM! =D The point is, if you go this route, you're back to having to 1) duplicate large parts of the ChatSetAttr command line within the query, which means 2) HTML replacements. If you find yourself here, there are ways that the Metascript Toolbox can help -- from right within the same ChatSetAttr command line, with only some initial setup required on your end, but no more effort required when you run the command. If this situation describes what you have going on, post back and I can show how you can use a single query to drive multiple, different results in different places in your command line. Or, if it doesn't describe what you have going on, maybe you could explain why your post described one goal but your example seemed to point at another... there might be other ways the Toolbox can help if I can understand your overall goal.
1734018997

Edited 1734019299
timmaugh said: I wouldn't solve it in the way I'm about to show -- see below for that. First, I just want to show the issue so that you know for the next time what is happening. You have characters in your ChatSetAttr command that normally act as control characters for the query -- and the Roll20 query parser isn't context-aware enough to know the difference. It only knows to watch for those characters to move to different parts of its parsing logic. To get around that, you have to use HTML replacements on the parts of the ChatSetAttr command line that will interfere with the roll query: These are the query-control characters to watch for: CHAR | TYPE | QUERY CMD ======|==============|========================= | | pipe | move to next query item , | comma | within query item, move to next component (ie, name to value) } | right brace | end query If you want these to not be interpreted by the query parser, you have to use their HTML replacements. Lots of people use their numeric versions (i.e., |), but I prefer the more human-readable versions:   | => |   , => ,   } => } Replacing those characters where they need to be interpreted by ChatSetAttr (rather than the query) would look like: ?{Are you clean?|Yes, !setattr --name Sunscale --clean|1|No, !setattr --name Sunscale --clean|0} That's the lesson of the query control characters... but... What I'd Really Do Normally, you can rewrite your line so that the command contains the query rather than the other way around. That will shorten (and simplify) your line: !setattr --name Sunscale --clean| ?{Are you clean?|Yes,1|No,0} No HTML replacements necessary. But I still have a question I Still Have a Question Your post said that you want to choose from multiple attributes, but your example was dealing with a single attribute and you're choosing whether or not to put a "1" in the value. One interpretation I can see for your post is that you need the player to answer the "Are you clean?" query, and then take different actions on different attributes for that character based on the response (ie, adding 1 here, making a 0 there, etc.). Having to use a single query to represent multiple different effects like this would mean, in standard Roll20 usage, that  you would HAVE TO structure the query the way you initially did -- where the query encloses (at least part of) the ChatSetAttr line. That is, within the "Yes, I am clean" portion of the query response  you would have the value of "1" for Sunscale, the value of "0" for Mudbath, and maybe a +5 for Oi_papi_looking_gooood. DON'T LOOK AT ME LIKE THAT -- I DON'T MAKE UP THE ATTRIBUTES; IT'S YOUR GAME SYSTEM! =D The point is, if you go this route, you're back to having to 1) duplicate large parts of the ChatSetAttr command line within the query, which means 2) HTML replacements. If you find yourself here, there are ways that the Metascript Toolbox can help -- from right within the same ChatSetAttr command line, with only some initial setup required on your end, but no more effort required when you run the command. If this situation describes what you have going on, post back and I can show how you can use a single query to drive multiple, different results in different places in your command line. Or, if it doesn't describe what you have going on, maybe you could explain why your post described one goal but your example seemed to point at another... there might be other ways the Toolbox can help if I can understand your overall goal. I did edit the post for clarity, but you must have been typing this great response already. I'm trying to make a toggle for an attribute. I have tried using the HTML replacements, but the chatsetattr syntax doesn't seem to understand them. In fact, the chat message doing that even with just a basic, one function chatsetattr command is: Setting clean|1 to  (empty)  for character Sunscale. However, this worked! !setattr --name Sunscale --clean| ?{Are you clean?|Yes,1|No,0} Problem solved.