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

Inline roll command and if/then statement macro functionality

February 15 (3 years ago)

Hello,

I'd like to ask for help on a thing I'm doing out of curiosity. I know there's an easier (and simpler, and probably more efficient) way to do this, but it's interesting to me to see what the boundaries I can push are. So:

This is (WIP) macro to automatically roll a hemocraft die (from Blood Hunter) using if-then statements from inline rolls. It doesn't, as of right now, work, but I've made the statements individually work.

I'd like some help making the situation I've created function, if that's at all possible!


&{template:simple} [[ [[{{@{Level},4}>5}*(1-0) + 0]] + [[{{@{Level},10}>11}*(1-0) + 0]] + [[{{@{Level},16}>17}*(1-0) + 0]], [[d4]], [[d6]], [[d8]], [[d10]] ]] {{rname=Haemocraft Die}} {{r1= $[[1]] $[[2]] $[[3]] $[[4]] $[[5]] $[[6]] $[[7]] [[({{$[[7]], 0} > 1} * ({(({{$[[7]],1}>2}*{({{$[[7]],2}>3}*({$[[6]]-$[[5]])}+$[[5]])}-$[[4]]) + $[[4]])}-$[[3]]) + $[[3]])]]}} {{normal=1}}


I can post an explanation of what each part means if necessary. Thanks!

Reusing rolls in this way sadly doesn't work, you can only perform a calculation on a roll once.

It looks like you're trying to roll a specifically sized die based on level. Using d4 for levels 1-4, d6 for 5-10, d8 for 11-16, d10 for 17+

This macro will perform that roll

&{template:simple} {{rname=Haemocraft Die}} {{normal=1}} {{r1=[[d[[4+2*{5,11,17}<@{Level}]] ]]}}
February 16 (3 years ago)

Edited February 16 (3 years ago)

Yeah, it seems really unlikely to work- and I appreciate the help- but I do actually have a way to do it (albeit one more focused on algorithms rather than what you've done). I'm moreso asking whether this could at all work- if I can find a way to nest the rolls in such a way that it's entirely just calling the inline rolls in the template's actual visual part, I'd say it should be able to work. As of right now, whenever I try to do that it gets an invalid inline function error- and I want to know if anyone's able to figure out the exact reason why.

In addition, it seems at least somewhat possible to nest things like that- but I'm not entirely certain. I'd like to ask for examples of what would/wouldn't work, if that's okay?

Thanks for the actual function, though! I'll store it for later, appreciated.

February 16 (3 years ago)
GiGs
Pro
Sheet Author
API Scripter

You'd have to describe exactly the process you are imagining before we can tell you if it'll work or not.

Rather than asking for exampls of what might work, which would be us simply guessing at what you need, why don't you say exactly what you need and we can tell you if it's possible on roll20 or not.

Generally speaking, pretty much anything is possible if your GM is a Pro subscriber and lets you write a custom script, but the standard macro language is a LOT more limited and lots of things you might imagine should be possible just aren't.

February 17 (3 years ago)

Alright, I can do that (or, at least, I'll try.)

I was hoping to figure out how (using very minimal mathematical expressions besides addition, multiplication, subtraction, and division) to make an automated die-roller for a given set of values incremented via level. As an example, maybe at level 4 you would have a 1d4 and at level 5 you would have a 1d8.

The method I approached this with (and the one I'm most interested in) is via a set of nested if/then statements. If (level) is greater than 5, test for whether (level) is also greater than 10, etc.. As for how I executed this, I used a series of inline rolls and testfor if/then statements to output a result- when done correctly, this would result in a way to output a true (1) or false (0) output for each test, as well as possibly result in an easy way to do the dice rolls (via reusing rolls via nested inlines.) However, I ran into the issue of not being able to do math on reused rolls. If there was a way to compute everything while in progress, it'd be much easier. Unfortunately my brain is also only able to handle so much complicated code jargon, so I was unable (on my own) to construct a single testfor chain to do this with.

I'm not certain it's possible, but it'd be very cool if it was (albeit probably also very difficult.)

February 17 (3 years ago)

Edited February 17 (3 years ago)
GiGs
Pro
Sheet Author
API Scripter

Can you describe what you are trying to do, without any reference to how you would do it on roll20?

Forget how you imagine it might be done, but instead just describe the game mechanic you are trying to create, as if we were players at your game table.

I can tell you that roll20 will not do if/then tests, it is impossible. As RainbowEncoder says, the method you are trying in the first post won't work.

But there are sometimes ways to fake an if/then test, depending on the situation. I'm looking at the partial information you have given and think there might be a way using a custom bult expression (like you attempted with your first post). But I don't have enough information to say one way or another.


At the moment you are asking "can we do this by this method?" - and that forces us to think in terms of the method you have chosen, but you don't know roll20's limits, so the method you have chosen may be the wrong one.

If instead you tell us what you are trying to achieve, we might come up with different methods that do work.

So, describe the complete mechanic, as if you were describing it to a player at your table, without mentioning roll20 at all. Then we can answer you.


On the other hand, if you are specifically asking, "can this method work?" - RainbowEncoder has already answered that: no.

As GiGs says, Roll20 doesn't support if/then and to reiterate roll results are limited to one usage with inline rolls.

It is possible to fake if/then using branch-less programming techniques if the entire macro can be represented as a mathematical expression without reusing random results. In order to do so your conditions have to return 1 if and only if it should output. Using the failure targets is a good way to do that with level-based expressions. So the example roll could also be written as

[[ [[{@{Level},0}>1f>5]]*(d4) + [[{@{Level},0}>5f>11]]*(d6) + [[{@{Level},0}>11f>17]]*(d8) + [[{@{Level},0}>17]]*(d10)]]

However this does mess up the critical highlighting and generally makes for confusing tooltips so I wouldn't recommend it.