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

Need help with inline rolls

So I am trying to do a thing with Chatsetattr where I can have a token macro for my paladin so it ticks off a channel divinity and a harness divine power resource from the character sheet, as well as add a spell slot that they picked back, and the macro for that works great and does what I need... It's not until I try to output a whisper in the chat using certain things where things go awry. Below is the macro, and I will make the part that I am having trouble with bigger than the other text the part I'm having a problem with. !modattr  --silent --name @{selected|character_name} --repeating_resource_$0_resource_right|-1 !modattr  --silent --name @{selected|character_name} --repeating_resource_$6_resource_left|-1 !modattr  --silent --name @{selected|character_name} --lvl?{what level spell slot?|1,1|2,2}_slots_expended|+1 /w "@{selected|character_name}" &{template:desc}{{desc= The following resources have been changed, these are their current numbers: **Level 1 Spell Slots** [[@{selected|lvl?{what level spell slot?|1,1|2,2}_slots_expended}+1]] **Channel Divinity** [[@{selected|repeating_resource_$0_resource_right}-1]] **Harness Divine Power** [[@{selected|repeating_resource_$6_resource_left}-1]]}} As you can see I am having trouble with that inline roll. I wanted it to ask what level spell they wanted to get back by repeating the question from this part " !modattr  --silent --name @{selected|character_name} --lvl?{what level spell slot?|1,1|2,2}_slots_expended|+1" so it would just put in that value without prompting another question. but I guess inline rolls go through before the question prompt command does and it says that the attribute that I tried to roll doesn't exist. is there a way to do this? or do inline rolls prevent you from doing question prompts in them. (P.S. sorry if some of the terminology is wrong, I make macros all day, but I don't know the names for things really)
1674605843
You’re right. You cannot put a query inside an attribute call because of the Roll20  Order of Operations . However I’m pretty sure Timmaugh will jump in with a MetaScript and explain how to do with with those scripts. :)
1674625557
timmaugh
Pro
API Scripter
Oh, yeah. Short answer, install Fetch and ZeroFrame and use this construction: [\][\]@(selected|lvl?{What level spell slot?|1|2}_slots_expended)+1\]\] Right in your command line. Just jam it on in there. Longer answer: metascripts are like setting the deck in a 2v2 card game. ____A____ | | D| |B |_________| C Player A is the dealer, and wants to give the ace to his partner, Player C. But Player A can't deal the ace to Player C until Player B has gotten a card, so to set the deck you have to set it up so that the delivery of the ace waits one card. If Player A wants to give himself a card, that has to wait until *3* cards are dealt. Similary in Roll20 metascripts, there's nothing you can do to change the speed of the query. It happens immediately (and only immediately) when a message is sent. You can't get something in "ahead" of the query. You have to wait to get the thing you want (the attribute) until after the query runs. That's fine, because after Roll20 parsing (including the query), the message passes to the set of installed scripts and metascripts can start working. So now we're getting an order that looks like:  Actions: Send command Roll20 parsing Get the attribute But you're not done... you  still have to handle the roll. When should the roll process? It can't process until after the attribute is returned (or you'll get a syntax error for the roll). And you know that the attribute isn't going to be returned until the query is done and the message has moved into the script stack. So handling the roll has to happen after the attribute retrieval: Actions: Send command Roll20 parsing Get the attribute Inline Roll The trick here is that although inline rolls happen "immediately" when a message is sent ("immediately" in the sense that they happen during Roll20's parsing as a part of the order of operations Jarren linked to), they don't ONLY happen immediately. We can re-trigger them by issuing a new message in the background (what ZeroFrame calls a "loop"). So we start with this in the command: [\][\]@(selected|lvl?{What level spell slot?|1|2}_slots_expended)+1\]\] We get the query resolution before the metascript loop gets started, changing the above to: [\][\]@(selected|lvl2_slots_expended)+1\]\] Fetch sees a fetchable construction: @(selected|lvl2_slots_expended) Maybe that returns a 2, leaving this part of the command line as: [\][\]2+1\]\] Finally, just before starting a new loop, ZeroFrame strips one level of deferral character away (the backslashes): [[2+1]] Which then gets resolved in the new loop.  Once all the metascript work finishes, the message is released to the rest of the scripts you have installed, and ChatSetAttr can do what it does.
Thank you for the info! I see what you were explaining in your previous message and I have been trying to find a way to circumvent the order of operations for a while lol. The problem I have is this template and it not showing the value I wanted highlighted by an inline roll in the "[[]]" brackets. I copied and pasted what you gave me, but it didn't give the right outcome that I wanted (Highlighted like channel divinity and harness divine power). I find it hard to describe these things sometimes lol.
1674667381
timmaugh
Pro
API Scripter
No worries... First, you did install both Fetch and ZeroFrame? If you did, then the next thing is that to use a metascript syntax structure, your command line has to start with a bang: ! ...even if you want to output to chat (like with a roll template). Then, if you want to output to chat, use the {&simple} structure from ZeroFrame. So that was on me for not realizing that you weren't needing help in a script-calling message (like something headed to ChatSetAttr), but actually in a message using a roll template. To make that work, change the roll template line to be: !/w "@{selected|character_name}" &{template:desc}{{desc= The following resources have been changed, these are their current numbers: **Level 1 Spell Slots** [\][\]@(selected|lvl?{What level spell slot?|1|2}_slots_expended)+1\]\] **Channel Divinity** [[@{selected|repeating_resource_$0_resource_right}-1]] **Harness Divine Power** [[@{selected|repeating_resource_$6_resource_left}-1]]}}{&simple}
Awesome! the output goes to the chat and it shows up fine, the only problem I have now is that it won't whisper it. could it be a problem with it calling that inline before calling the whisper? (when I click the button, the chatsetattr does it's thing and marks off the required resources, and nothing gets inputted into the chat if the whisper command is added)
1674700911
timmaugh
Pro
API Scripter
If you swap out the recipient of the whisper does it work? Change it to be "gm" and see if you get the whisper, then. Also, does the character have any special characters in their name? Deferring the inline won't matter to the timing, since the ZeroFrame loop will keep running until there isn't any more meta-work to take care of, then it will output the final message at the end (complete with any declared whispers).
I tried switching the names and it didn't work, and the only special thing about the character is the space in his name, which is why i put the quotations around "@{selected|character_name}"
1674746231
timmaugh
Pro
API Scripter
I mocked up a similar setup in one of my games, and it's working for me. Any chance of inviting/promoting me to gm in that game so I can take a look?
1674746261

Edited 1674747685
GiGs
Pro
Sheet Author
API Scripter
Have you tried with a single word name, and no space and apostrophes? It shouldnt fix it, but its worth checking every possibility.