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

Can't find a way to use MathOps

Hello Everyone o/ I try to use the "MathOps" Script, I had installed it with the "One-Click Install".  And I have tried to use it with the "Exemple" that we can find in the Official Forum Thread  and the Wiki Parts of MathOps . Tried to use "/r {& math (2+3)/4}" and inline bracket "[[ {& math (2+3)/4} ]]". But the Every Time the result is an Error Message : And the API of my Games didn't return Any Error or Crash.  I also Tried to Run it on a Games without any other API Script... Did I have forget to do something ? I do not Use the Meta Tool Box but it's said that it's do not Require it ? 
1631896610

Edited 1631896861
vÍnce
Pro
Sheet Author
I could be wrong(often...), but I believe MathOps is a script that falls in a category that can be utilized by other scripts(meta), not a standalone script that accepts command via chat per se. Tim would be best suited to comment on this.
1631897200

Edited 1631897541
Andreas J.
Forum Champion
Sheet Author
Translator
The error message makes it sound like the API isn't installed or working. Try restart the api sandbox and try again. And installing the meta toolbox is worth a try. Do you have any other APIs installed in your game? I've never used it before, and got the same results with trying {& math 2*2} Installed ZeroFrame and ran the !0 config , which confirmed that at least zeroframe sees that mathops is installed, but have no idea how it. vÍnce said: I could be wrong(often...), but I believe MathOps is a script that falls in a category that can be utilized by other scripts(meta), not a standalone script that accepts command via chat per se. Tim would be best suited to comment on this. Ugh, this is what I was afraid of, the whole bag of tools are powerful and versatile, but the bar to try using them is so high I've never tried even use them. Just not for me, clearly.
1631898701

Edited 1631900775
I try to find something to be able to do "Power/Exponentiation" in "Inline" and the title of the MathOps. " MathOps - inline math operations and nested formulas " make me think that it's what I searched cause he has listed "Pow" in the list of command that can be called with MathOps and the title speak about Inline Math.  I have a Damage Calculation that use a formula : And I wanted to integrate it through a Macro. I have already done it with simpler Calculation . And thinked that MathOps would be able to give me the "Power/Exponentiation" command that I Need for it ! Then for me the macro would look like Something like that :  "Damage : [[1d10 + (@{Selected|WeaponDamage}*{& math pow(1.10, @{Selected|PrimaryStat}-1})]]" Andreas J. said: The error message makes it sound like the API isn't installed or working. Try restart the api sandbox and try again. And installing the meta toolbox is worth a try. Do you have any other APIs installed in your game? I've never used it before, and got the same results with trying {& math 2*2} Installed ZeroFrame and ran the !0 config , which confirmed that at least zeroframe sees that mathops is installed, but have no idea how it. - Every new Api Script that I use are firstly use "Alone" in a empty test game for avoid conflict. (Then yes I have other Script but for the moment they are "I guess" not a problem) - Cause it's speak about "Inline Math" I Mostly tried to use the "Inline Bracket" in my case I had tried [[ {& math 2*2} ]]. But the message as you said give me the Idea that it's not installed or not working. - I have tried to install ZeroFrame with it but when I do and try again to call MathOps with the "Math Tag" in inline bracket : " [[  {& math ... } ]]. I got the Same Result than without ZeroFrame.
1631905437

Edited 1631914180
timmaugh
Pro
API Scripter
Hey, Damon, you're examples are very close. Let me see if I can shed some light. The bulk of this reply will be explaining/educating how/why the metascripts do what they do. If you want to jump to a working version, see the TL;DR header at the end. Ok, here we go... The metascripts are still scripts in that they can only operate if the message is pre-pended with an exclamation point (to send it to the API). After that, it's a matter of: 1) managing the order of operations 2) including the syntax tokens that would trigger the metascript you want to use, and then 3) leaving the message in the state that you need in order for the next operation (a regular script or a simple chat message) If you can break things down into these segments, it does get easier. Exclamation Point Having to start with an exclamation point means we can't use the /r notation to trigger a roll. Messages that begin with /r are never sent to the API, so the metascripts never know to do anything with them. In order to use metascripts, we have to start with an exclamation point and use inline roll notation (double brackets) for our rolls. As a by-product, we need to be aware that messages that begin with an exclamation point are never sent to the chat, so we need to have a way to do that part, manually. Order of Operations Beyond Roll20's order of ops , you should think about the larger order... Roll20 Parsing => metascripts => normal scripts If you have ZeroFrame installed, the first two items in that list become a loop, so that after Roll20 parses the message and metascripts make changes, the message is exposed to the Roll20 parsers again. || || ||: Roll20 Parsing => metascripts :|| => normal scripts || || The loop operates until no further metascript changes are detected. The other change with ZeroFrame installed is that the metascripts can be ordered within that portion of the loop. The metascripts would normally operate in the order they were installed, but with ZeroFrame installed, they have a defaulted order. You can alter that order, of course, but the point is that you have to pay attention to the order to know which metascripts will process before others. Syntax Tokens Each metascript looks for its own tokens to take actions on the message. For MathOps, that is the {& math} token. ZeroFrame offers an ordering tag ( {&0} ), a roll extraction tag ( .value ), and a tag to output a non-API message ( {&simple} or {&flat} ). Those last two become important in the next part. What Comes Next When the metascripts are finished, the message moves on. If the message is still an API message, it will not hit the chat by default (we can change that -- read on). It will continue to move through the installed scripts, giving each the opportunity to take action. As an example: !The result of 2+2 is {&math 2+2} When that MathOps token condenses, the resulting command line will be: !The result of 2+2 is 4 But now that command line moves on to the other scripts you have installed. Standard scripts typically pick up the message based on the opening characters, like !token-mod, !setattr, etc. In our case, no script is going think it should take action based on our new command line. On the other hand, if we were using a MathOps construction in a TokenMod command, this would be exactly what we wanted: !token-mod --on emits_bright_light --set bright_light_distance#{& math @{selected|level}*2} This time, after Roll20 parsing, MathOps sees the {& math } construction as: {& math 4*2} (assuming the level of the character is 4) The final command line, after metascript processing, is: !token-mod --on emits_bright_light --set bright_light_distance#8 This time when the message moves on, TokenMod will pick up the message and see the 8 that was rendered by MathOps. In order to output a rendered message to chat, we need to use the {&simple} tag from ZeroFrame. That will release the message to the chat interface rather than letting it continue through the rest of the installed scripts. This is what we have to do if we want to utilize the metascripts, but see the result in the chat (say, in a roll template). Returning to the first example: !The result of 2+2 is {& math 2+2}{&simple} The {&simple} tag says that after metascripts have finished, send the resulting message content to the chat. Here's the same thing in a roll template: !&{template:default}{{name=I Can Do This?}}{{The result of 2+2 is={&math 2+2}}}{&simple} Advanced Steps If you want to use MathOps in an inline roll, we have to think through the order of operations again. In the listed example: [[ {&math (2+3)/4} ]] What happens is that Roll20 parses the message first, but can't process the inline roll with the MathOps construction. We need the MathOps metascript to run BEFORE the inline roll. In this case, we can't let the inline roll be recognized by Roll20 until we are ready. I call this deferring the inline roll, and it involves adding backslashes to the brackets (as well as a closing bracket to each opening bracket -- don't ask, there's a quirk of Roll20 parsing that requires this added character): [\][\] {&math (2+3)/4} \]\] In a message prepended with an exclamation point (to send it to the API), this formation will go undetected by the Roll20 parsers on the first pass, allowing the MathOps construction to parse out to 1.25. On the second pass of the loop, ZeroFrame will escape the inline roll by one set of backslashes before initiating the Roll20 parsers again. At that time, the inline roll is detected and processed. Remember that if you want to see this roll in your chat (instead of sending on through the rest of the API scripts) you still need to include ZeroFrame's  {&simple} tag: ![\][\] {&math (2+3)/4} \]\]{&simple} Taking this to another level, imagine a mechanic where you have a roll composed of a number of d10 and d4. You get your level divided by 5 (rounded down) in d10. You get the remainder (the modulus) in d4. So a level of 6 should be 1d10 + 1d4. A level of 12 should be 2d10 + 2d4. We can get the d10 using Roll20 inline roll syntax: [[floor(@{selected|level}/5)]]d10 ... or MathOps syntax: {& math floor(@{selected|level}/5)}d10 And we can get the d4 with MathOps: {& math @{selected|level}%5}d4 Since we have to use MathOps for one of them, we have to defer the inline rolls that depend on the MathOps construction one time to let MathOps parse out. The final version will look like one of these two options: ![\][\] [[floor(@{selected|level}/5)]]d10+{&math @{selected|level}%5}d4 \]\]{&simple} ![\][\] {&math floor(@{selected|level}/5)}d10+{&math @{selected|level}%5}d4 \]\]{&simple} TL;DR Make sure you start with an exclamation point to trigger the metascripts. Make sure you include  {&simple} somewhere in the message if you want it to hit chat (instead of continuing on to another script). Make sure that if you need an inline roll (which you sometimes don't need/want if you can do it in MathOps) you use inline roll notation, and defer your roll if it would rely on MathOps, giving MathOps time to parse itself out of the way. REQUIRED SCRIPTS: ZeroFrame and MathOps
1631906622
timmaugh
Pro
API Scripter
DamonReborn said: *snip* *snip* Then for me the macro would look like Something like that :  "Damage : [[1d10 + (@{Selected|WeaponDamage}*{& math pow(1.10, @{Selected|PrimaryStat}-1})]]" Hopefully you see from the previous message that you need to 1) start with the exclamation point, 2) defer your inline roll, and 3) output a simple message if you want it to register to chat. Also, your power function involves a math operation happening on one of the arguments, so we need to make sure that slots in to the correct position BEFORE the housing MathOps syntax token parses. We can do that using an inline roll and extracting the value: [[0d10+@{selected|PrimaryStat}-1]].value ...or with another MathOps construction: {& math @{selected|PrimaryStat} - 1} However, the second option would require that the outer MathOps token be deferred one time, to allow the inner one to complete: {\& math pow(1.1, {& math @{selected|PrimaryStat} - 1})}  ^ -- deferral character Deferring the outer MathOps would require a second deferral to the encompassing inline roll, so I'd just opt for the first version. The end result would be something like: ![\][\]1d10+(@{selected|WeaponDamage}*{&math pow(1.1, [[0d10+@{selected|PrimaryStat}-1]].value)}\]\]{&simple} Sending that line through chat should get you the result you need. Obviously if you need the same roll in an API script command, you wouldn't want the {&simple} tag.
Thank you for the explanation and the answers o/  Sadly I had inverted the Syntax, but after some modifications this one give what I wanted and work perfectly :  ![\][\]1d10+round(@{selected|WeaponDamage}*{&math pow(1.1, [[@{selected|PrimaryStat}-1]].value)})\]\]{&simple} I had inverted both Pow arguments, Pullet out a 0d10 and added a ")" . I think your explanation is really complete and I will try to do what I aim for with that ! Thank you o/  (But for sure I have some hard time understanding the (Deffering Mechanism) you speaked about. I understand the one with the [\], cause it's a weird rule for roll20 probably. But the one with the {& math ...} call. It' seem logic... I think I will probably get it with a little more thought and dedication on my side. I will then probably Call Back if I need help for it but for the moment everything is fine !)  I also put some more information here for me later: I understand it's because of the presence of !note but Without really understanding why. Removing {&simple} at the end of the script is necessary if I want "!note" to work with it. !note Damage : [\][\]1d10+round(@{selected|WeaponDamage}*{&math pow(1.1, [[@{selected|PrimaryStat}-1]].value)})\]\]
1631927554
timmaugh
Pro
API Scripter
Yes, sorry... for some reason I thought I needed the 0d10 to trigger a math-only roll. Apparently not on this one. Really quickly about {&simple} and other scripts... When a message is sent to the stack of scripts installed for a game, it moves through them in order, earlier-installed scripts to later-installed scripts.(Meta-scripts happen to line-jump this to get in sooner.) The message keeps getting handed off, one script to the next even AFTER the intended script has had a chance at it. So if you install TokenMod and then install ChatSetAttr after, a message that is intended for TokenMod will still make it to ChatSetAttr AFTER TokenMod is done. Every script gets a chance at the message, they just have to wait their turn. The way they are written typically results in only one script taking action based on a given message. So think of your scripts like a stack: Roll20 parsing MetaScript 1 MetaScript 2 MetaScript 3 Script 1 Script 2 Script 3 Script 4 It works top down, one time. If you have TokenMod installed in the Script 2 slot, it receives the message only after the metascripts AND Script 1 are done. When it has finished with the message, the Script 3, and 4 scripts get a chance at taking action. With ZeroFrame installed, the stack looks more like: Roll20 parsing ZeroFrame => loop over other metascripts Script 1 Script 2 Script 3 Script 4 This matters because the way ZeroFrame invokes the Roll20 parsing at each pass of the loop is to issue a new message ... which it then catches and exposes to the metascripts again. As long as they make changes, the loop continues. The {&simple} tag is evaluated at the last passage of the loop (when there are no more meta constructs to parse). It tells ZeroFrame to issue the message one more time, this time without the leading exclamation point, so it isn't an API message anymore. In effect, it short-circuits the stack and keeps the message from ever reaching the other scripts. So without the {&simple} tag, the message stays in the API stack, waiting for an API to pick it up and take action. With the {&simple} tag, it is reissued as a simple chat command, and the standard scripts never see it. Maybe that makes sense. Maybe that's too deep in the metasauce.