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

How to allow with a script players to insert a modifier in a menu using gui?

While working with the roll20 API, specifically the sendchat with async callback, I noticed a problem. I can't find a way to allow players to select options included in my scripts. Inside the provided doc, there are ways to access characters attributes and abilities but there is no reference on how to get user input by gui. In other words, is it possible to fire the command ?{modifier} to show the selection menu to the players and get back with their choices?
1576327188
The Aaron
Roll20 Production Team
API Scripter
It is not.  What we usually do is either create a macro/ability that does the query up front and then passes all the parameters as arguments to the initial api command, or we prompt in chat with multiple API command buttons and get dynamic input that way. 
1576429068

Edited 1576429236
Thank you for clarifying this, but how could I send the parameters from macro to api commands?
So for a typical command, let's say.. "!doWork", you can make a list of parameters (optional or required) that are passed in as a pipe-delimited list.  For example: !doWork @{selected|strength}|@{target|armorClass} For the sake of this example, we'll say the selected token's character has a strength of 14 and the target has an AC of 21. Which will get passed into the chat:message handler's callback function as the first argument's content property. on('chat:message',function(msg){     if(msg.type === 'api'){         let command = msg.content;         if(command.indexOf(' ') > -1){             command = command.split(' ')[0];             commandArgs = msg.content.replace(command + ' ','').split('|');         }         if(commandComponents[0] === '!doWork'){             //commandArgs[0] === "14"             //commandArgs[1] === "21"             //Remember that these come in as strings, so if you want to do math on them, parseInt or parseFloat them first when you assign them.             //If you need arguments to be required and/or of a certain type, do all validation when you assign them. Failfast implementations help minimize resources consumed.             let strength, ac;             if(commandArgs[0]                 && strength = parseInt(commandArgs[0]) !== 'NaN'                 && commandArgs[1]                 && ac = parseInt(commandArgs[1]) !== 'NaN'){                 (command code here)                 //Note: I don't remember if assignments and boolean checks can be used in line like that in JS, but adjust accordingly if they can't.             }                      }     } })
Dear Charles,  Thank you very much. I will give it a try asap and let you know.
Ok,   I have looked at the script. I already know how to access attributes and abilities from tokens or characters. What I need is a way to let the player dynamically give me a modifier, like what happens when someone writes /roll ?{modifier} Can you please help me with that?
1576518703
GiGs
Pro
Sheet Author
API Scripter
It's not going to be easy to answer that without knowing what your script is meant to do and how it accepts inputs. You're not likely to be using the /roll command with a script input for example. In Charles example, you can easily do !doWork ?{first modifier|0}|?{second modifier|0} Your script needs to be set up to interpret the input, and your input has to be formatted to match that. 
1576594783
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Yep, it's important to remember that the API message handling sees the message in it's parsed form, so queries are handled exactly as attribute and ability calls, and rolls are; they're expanded by the chat system and that parsed message is what the API sees.