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

Scriptcards: ? -and Question

1697402487
Essen
Pro
Marketplace Creator
When I try to use -and in a comparison, I get a weird issue.  Can anyone tell me why? !scriptcard {{ --=Var1|1 --=Var2|2 --?[$Var1] -eq 0 -and [$Var2] -eq 1|1 --?[$Var1] -eq 1 -and [$Var2] -eq 1|2 --?[$Var1] -eq 1 -and [$Var2] -eq 2|3 --?[$Var1] -eq 2 -and [$Var2] -eq 2|4 --?[$Var1] -eq 2 -and [$Var2] -eq 3|5 --?[$Var1] -eq 3 -and [$Var2] -eq 3|6 --?[$Var1] -eq 3 -and [$Var2] -eq 4|7 --X| --:1| --+1|One --<| --:2| --+2|Two --<| --:3| --+3|Three --<| --:4| --+4|Four --<| --:5| --+5|Five --<| --:6| --+6|Six --<| --:7| --+7|Seven --<| }} That outputs this: I'm not sure why it outputs anything other than 3.
1697420105

Edited 1697420343
Andrew R.
Pro
Sheet Author
Have you checked the Mod Console for error messages?  You jumped (goto) to label —:3 when you should have made a subroutine call.  --?[$Var1] -eq 1 -and [$Var2] -eq 2|>3
1697424139

Edited 1697425392
Essen
Pro
Marketplace Creator
Nothing at all in the console.  What's odd is... With --?[$Var1] -eq 0 -and [$Var2] -eq 1|1 --?[$Var1] -eq 1 -and [$Var2] -eq 1|2 --?[$Var1] -eq 1 -and [$Var2] -eq 2|3 --?[$Var1] -eq 2 -and [$Var2] -eq 2|4 --?[$Var1] -eq 2 -and [$Var2] -eq 3|5 --?[$Var1] -eq 3 -and [$Var2] -eq 3|6 --?[$Var1] -eq 3 -and [$Var2] -eq 4|7 --+Bottom|This got to the end. --X| I still got. .. But with  --?[$Var1] -eq 0 -and [$Var2] -eq 1|>1 --?[$Var1] -eq 1 -and [$Var2] -eq 1|>2 --?[$Var1] -eq 1 -and [$Var2] -eq 2|>3 --?[$Var1] -eq 2 -and [$Var2] -eq 2|>4 --?[$Var1] -eq 2 -and [$Var2] -eq 3|>5 --?[$Var1] -eq 3 -and [$Var2] -eq 3|>6 --?[$Var1] -eq 3 -and [$Var2] -eq 4|>7 --+Bottom|This got to the end. --X| I get... Which is good. I just don't understand how, since the wiki says....  :Label If just a label is specified, execution will branch to that label when the comparison is matched. NOTE: You cannot use a standard Return (--<|) statement to return to the Conditional (--?) statement and resume the script. Example:  --?[$AttackRoll.Total] -ge [$TargetAC] |Hit |Miss >Label If a label name is preceded by a ">" character, a gosub branch will be performed. In this case, parameters can be passed to the subroutine by separating them from the label and each other with semicolons (;). Parameters that can contain a semicolon (like token/character IDs) should be surrounded by double quotes. Example:  --?[$AthleticsRoll.Base] -gt 8 |>AthleticsSuccess;@{selected|athletics} |>AthleticsFailed;@{selected|strength} How are 4-7 activating if --<| doesn't send it back up with that label? Is it all getting shoved together and running as true because that one step is true? I don't understand how it all got conjoined. This does seem to fix my main issue, though.
I think in your original without the gosub call, the --<| return is ignored and you just fall through the rest of the code. So the top section is run, matches your conditional to go to Label 3 and then falls through 4 through 7. You don't ever go back to the top section and run the other conditions. You could check that with some debug output statements in the top section to confirm. ScriptCards will just fallthrough code though. You can also see this if you use re-entry buttons to enter branches. They can just fall through the code after running.
1697429307
Andrew R.
Pro
Sheet Author
Joshua is correct. If you Goto a label, the --< does nothing and control flow continues to the end of the script.  I recommend reading about structured programming and using it with ScriptCards. 
1697448459
Essen
Pro
Marketplace Creator
Ah, that makes sense. Thanks!