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

Negative values ​​in the formula of a button does not work

Hello everyone I have a problem with a formula in a button. I roll 1d100 then I compare the result to the value of the attribute + bonus. So I created a button with this formula: /gmroll 1d100<[[@{level_com_credit}+@{bonus_com}]] This works perfectly unless the bonus is negative. Then I have this error message: SyntaxError: Expected [0-9] but "-" found. When I do the test on the command line it works smoothly: / gmroll 1d100 <[[80 + -2]] How to solve this little problem?
Nobody can help me???
1409845799
Paul S.
Sheet Author
API Scripter
Can't think of a way of helping without getting a copy of your HTML short of creating a temp char sheet (which I don't want to do). So, paste up a copy of your HTML and ref the line # that the button code is on. I'll take a look at it.
1409856464
Actoba
Pro
Sheet Author
If the attributes you mentioned in your formula are actually calculations and not a simple entered value then it's probably something to do with the order of operations and bracketing that causes the issue...remember that when you use an attribute in a macro it expands it out replacing it with the full formula and not the result of the underlying formula. In short, check how the attributes you reference are calculated.... For example : @{x} = 10*@{y} @{y} = 1 + 2 In this example if you used @{x} in a macro you would expect to get a result of 30....but you would actually get a result of 12 because of the way it gets evaluated - @{x} = 10*@{y} @{x} = 10*1+2 Therefore, because of mathematical order of operations the multiplication is done first so the end result equals 12. To fix this example you could change @{y} to be as follows - @{y} = (1 + 2) Which would then make @{x} = 10*(1+2) = 30
1409862036

Edited 1409862189
Gauss
Forum Champion
What are the values of your attributes? If the sum of @{level_com_credit} and @{bonus_com} is a negative then the inequality will not work. Solution: [[{@{level_com_credit}+@{bonus_com}, 0}kh1]] However, from the error you got it sounds like that field only wants numbers and is not accepting the negative sign. If that is the case I suggest looking at how people have included negative signs in their fields.
It works! Thank you all for your attention and especially to Gauss who gave me the solution!
1409913407
Gauss
Forum Champion
What was the problem (and solution)? :)
1409930839

Edited 1409931102
In this formula, when @{bonus_com} is a negative value that does not work: <div> <div><input type="text" name="attr_conn_firstaid" value="Premiers soins" disabled="true"/></div> <div><input type="number" name="attr_level_conn_firstaid" value="0" /><button type="roll" value=" /gmroll 1d100<[[@{level_com_credit}+@{bonus_com}]] " name="roll_firstaid" /></div> </div> With the one you pointed out to me it works <div> <div><input type="text" name="attr_conn_firstaid" value="Premiers soins" disabled="true"/></div> <div><input type="number" name="attr_level_conn_firstaid" value="0" /><button type="roll" value=" /gmroll 1d100<[[{@{level_conn_firstaid}+@{bonus_conn}, 0}kh1]] " name="roll_firstaid" /></div> </div> (Sorry I do not know the tag to display a clean code for the script.) I confess I do not understand how to read the syntax of what you gave me. I looked on the wiki but I did not find any explanation. If you could explain it to me I will be grateful.
1409932873
Lithl
Pro
Sheet Author
API Scripter
Torbor said: Sorry I do not know the tag to display a clean code for the script.) Click the "Formatting" button at the top-left of the Post Reply box and select "Code" Torbor said: I confess I do not understand how to read the syntax of what you gave me. I looked on the wiki but I did not find any explanation. If you could explain it to me I will be grateful. {mumble, 0}kh1 will take the higher value of "mumble" or 0. kh1 means "keep high 1"; the dice engine supports keeping more than one of the items in the group, as well as keeping the low values instead of the high values (kl1, for example).
1409937137
Tom
Plus
Sheet Author
It adds an extra step, but did you consider adding "-?{Penalty|0}" to your roll formula?