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

Logic in Macro? (missing attribute)

Running a custom game (Cataclysm RPG), and just using Attributes for the characters, and made some macros to let them do stat checks easily.   I'm tempted to do something similar for my monster tokens, but running into an issue that I can't seem to find a way to do basic "if/else" logic in the macros.  IE: I've got a token action like: &{template:default} {{name=@{selected|token_name}}} {{Physique=[[#d0 + @{selected|Physique}]]}} But of course if I select a token that I have, that I made quickly and doesn't have a character sheet attached (and therefore, no attributes).  It gives an error w/ " No character was found for 'selected' I'd like to have a way for it to detect that there is no character sheet (and/or that the character sheet doesn't have a Physique attribute), and to then prompt me instead as if I'd done a roll query. Does that feature not exist?
1593015390
David M.
Pro
API Scripter
AFAIK, not without writing an API script (Pro subscribers only)
1593016619
GiGs
Pro
Sheet Author
API Scripter
Macros don't support if/then expressions at all. For situations like that, you need two separate macros - one for characters with a character sheet, and one for those without.
Boo?   I would have expected that to be a fairly common thing.   Just a basic "If not X try Y" kind of syntax, so you could check a couple attributes (if equipped weapon, else if strength value, else prompt)
1593018343
GiGs
Pro
Sheet Author
API Scripter
Yes, roll20 has a few shortcomings of this nature. Little things its missing that would make a massive difference in usability for free users.
1593070252
Ziechael
Forum Champion
Sheet Author
API Scripter
It would take some effort depending on how many of these macros you have but you could insert a query? The @{selected|token_name} should work since that is an entity of the token and not a linked sheet so I'll just address the attribute call: &{template:default} {{name=@{selected|token_name}}} {{Physique=[[#d0 + ?{Sheet attached|Yes,@{selected|Physique}|No,?{Value|0}} ]]}}
1593100532
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Just as a point of clarification, the Macro syntax is not a programming language, just a specialized dice roller and chat reporter. It does not have the features of a programming language, like the ability to set variables (it just accepts user input), looping, or conditional branching. If you need those things, that's what the API is for.
1593159144
Ziechael
Forum Champion
Sheet Author
API Scripter
Like a dog with a bone I can't just give up on an issue... a query is useful but it's a whole extra click and no-one wants that! Try this setup instead, first you need to create a custom attribute on each sheet called something like 'safety' (yeah, I know... more work BUT you could use an existing sheet attribute if there is one you don't ever use), set the value to 0 Then: &{template:default} {{name=@{selected|token_name}}} {{Physique=[[#d0 + @{selected|safety} @{selected|Physique} &{noerror} ]]}} The above will prefix existing attributes with a 0 which will get stripped out of calculations but supply a 0 value when no attribute exists, the 'noerror' tag will prevent the display of those pesky 'no attribute exists' messages.