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

Confirmation promt

I am not very skilled at macro's and any help would be appreciated. I got a macro working that will add a status effect to a token and send a message to the chat " [name] has fallen asleep." . Players have access to this macro, and it's used to let them choose when to rest somewhere. I want to add a little confirmation prompt that says "Are you sure you want to fall asleep?" with a button yes/no. Is it possible and if yes, could I see an example of how I would do this? 
1722949830
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
You could probably do it with a drop down. Can you post the text of your current macro?
!token-mod --set statusmarkers|+Condition_Sleep_02::6592706 @{selected|token_name} fell asleep.
One way you could add a prompt is by using ScriptCards . !script {{ --&MarkerName|Condition_Sleep_02::6592706 --#title|Sleep --#sourceToken|@{selected|token_id} --#reentrant|sleep[*S:t-id] --#whisper|self --+|[c][b]Are you sure you want to sleep?[/b][/c] --+|[c][rbutton]Yes::Sleep;[*S:t-id][/rbutton] [rbutton]No::Decline;[/rbutton][/c] --:Done| --X| --:Sleep|TokenId --#hidecard|0 --#whisper|0 --+[*[&reentryval]:t-name]|has fallen asleep --@token-mod|_ids [&reentryval] _set statusmarkers|+[&MarkerName] --^Done| --:Decline| --#hidecard|1 --^Done| }} That will whisper to the calling player with the prompt and then if they say yes it will put a message in chat and call token-mod to add your marker. One thing to note is that you will need to check your token-mod configuration to allow players to use --ids !token-mod --config I am sure there are other ways to accomplish this as well but this is one way using ScriptCards. Let me know if you have any questions about this.
1722955628

Edited 1722955728
timmaugh
Pro
API Scripter
EDIT: Joshua with the ScriptCard ninja from the top rope! That's the sort of ScriptCard solution I mention, below. But, if you want to see the metascript version of using conditionals, read on... Roll20 offers no "built in" conditional syntax. Without a Pro sub, you're limited to workarounds like having 1-item rollable tables for IF result and for the ELSE result. With only 1 item in the rollable table, you know you're going to get it from the table once you arrive at which table to pull from. As you can imagine, that method doesn't scale well. Happily, with a Pro sub, there are other options. If a script (like TokenMod) doesn't allow in-line conditionals, there are still at least 2 options. I'll show the Metascript Toolbox approach, but I'm sure someone more knowledgeable in ScriptCards (the other option) can show you that method. I know that ScriptCards is its own thing, and can either modify the token, directly, or issue the TokenMod command to do it. On the other hand, the Metascript Toolbox is a way to give functionality to other scripts (like giving conditional evaluation to TokenMod) so it will work right in the TokenMod line. One thing about your starting line, however... I think you lost a line break somewhere along the way. I think the TokenMod command should be on a different line from the report that players see. That's how I'm going to approach it, anyway. That means this is the command I'm starting with: !token-mod --set statusmarkers|+Condition_Sleep_02::6592706 @{selected|token_name} fell asleep. So, since there are two lines that will *both* need to be conditioned, I'll put them in a batch and use the same conditional check for them both: !{{ {&if ?{Are you sure you want to fall asleep?|No|Yes} = Yes} !token-mod --set statusmarkers|+Condition_Sleep_02::6592706 @{selected|token_name} fell asleep. {&end} }} About the Batch These conditionals will work in a single line, and you can use the same query response across different commands even outside of a batch... ...if you feel the "but" coming, you'd be right. First, just to make sure it's clear what I'm saying, you can enclose conditional logic in the TokenMod line: !{&if ?{Are you sure you want to fall asleep?|No|Yes} = Yes}token-mod --set statusmarkers|+Condition_Sleep_02::6592706{&end} That will remove all of the TokenMod verbiage from that line if the conditional doesn't check out, leaving the TokenMod code nothing to detect in the message when it gets a chance at it. Then, you could similarly do, in the reporting line: !{&if ?{Are you sure you want to fall asleep?} = Yes}@{selected|token_name} fell asleep. {&simple}{&end} Again, you're using the same query response (the second -- and subsequent -- time(s) you reference a query you don't have to include the possible responses), and the conditional is all contained to that one line. If the condition check returns "false", nothing will be left of the command, and no message will hit the chat. So what about that "but"? First, notice that we had to duplicate all of the IF conditional language. The only part that was shortened was the query (leaving off the responses), but there's still a lot of extraneous stuff. Also, notice how the second line had to start with a bang (!) and end with a {&simple} -- the bang allows the metascripts to get to work, and the {&simple} tells them to output the resulting text when they finish. That's even *more* verbiage. But the bigger problem is the dropped line bug that's still lurking about. Sending separate commands through the chat at the same time (multiple, separate commands) makes it possible that one or more would be dropped along the way. Typically you don't drop the first command, so in your case you might get the TokenMod command to run, putting the marker on the token, but then you wouldn't get the second command, reporting that the token has fallen asleep. Here's a simple example. I ran this command through my game to confirm that the same query could be used across lines. There are two lines, and each should output something to chat, based on what I choose from the query: ! First line   {&if ?{Yes or No|Yes|No} = Yes}yes{&else}no{&end} {&simple} !Second line {&if ?{Yes or No} = Yes}Yes{&else}No{&end}{&simple} I ran that twice in my game. The very first time I ran it, though, I had a dropped line. Running it twice should have output 4 lines (a "first line..." then a "second line...", then repeated). Instead, I got: All of that to say that THAT is why I went with the batch. It simplifies the amount of verbiage you need and makes sure both command lines are sent and handled.
Wow, Timmaugh! That's a thorough explanation! It was easy to understand, and I really enjoyed going through the thought process as you described it. Reading it, I realize there is so much more I want to learn. Thank you for taking the time to type this all out for me. I tested it out and got it working! And Joshua N., also much thanks for showing me an example of how prompts with scriptcards work! Your example was also very easy to understand. I also tested this out and have been successful in making a prompt. I have enough to go on from here and play around with these possibilities and design something cool for my group, thanks both of you!
With the help of Joshua, I created the following macro. I thought to post it here, in case it will help anyone who's looking for something similar. This macro will give a whisper to the player, asking them if they want to add the sleep status or not. When (de)activated it will automatically (un)lock the player token and give it a status icon. I'm using a custom statusmarker icon, you'll have to change the 2nd line to put in your own statusmarker icon ( MarkerName|Condition_Sleep_02::6592706 ). !script {{ --&MarkerName|Condition_Sleep_02::6592706 --#overridetemplate|gothic --#emoteBackground|[#00FFFFFF] --#title|Sleep and wake up --#sourceToken|@{selected|token_id} --#reentrant|sleep[*S:t-id] --#whisper|self --+|[c][b]Are you ready to fall asleep or wake up?[/b] Remember: Only the keeper can tell you when to wake up.[/c] --+|[c][rbutton]Sleep::Sleep;[*S:t-id][/rbutton] | [rbutton]Wake up::Decline;[*S:t-id][/rbutton][/c] --:Done| --X| --:Sleep|TokenId --#hidecard|0 --#whisper|0 --+[*[&reentryval]:t-name]|has fallen asleep. You cannot move or perform actions unless the keeper tells you otherwise. --@token-mod|_ids [&reentryval] _set statusmarkers|+[&MarkerName] lockMovement|on --^Done| --:Decline| --#hidecard|0 --#whisper|0 --+[*[&reentryval]:t-name]|has woken up. --@token-mod|_ids [&reentryval] _set statusmarkers|-[&MarkerName] lockMovement|off --^Done| }}