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 .
×
Advertisement Create a free account

White space in input fields?

1626277519
Jason M.
Pro
API Scripter
I've been using Roll20 since COVID hit, and I love it. This past month the missus treated me to a pro subscription, and I've been screwing around with the API, doing an initial test script to make managing status effects, duration, and marker management easier. I've basically got it working (with heavy how-to borrowing from other scripts). However, one thing kind of bugs me. My command (with a menu wrapped around it, so forgive the verbosity) looks something like this: '!statustracker add_status @{selected|token_id} ?{Effect Name} ?{Duration in rounds (-1 for permanent)} ' + markerSelect The problem is that the input for "Effect Name" cannot have spaces in it. The upshot is that adding space characters shifts the input params, and things go sideways.This isn't the end of the world, but since that field is displayed in chat and the turn tracker, it would be nice to have the text look somewhat neat, i.e. "My Effect" vs "My_Effect". My question (that I haven't been able to find an answer to): is there a way to allow the input to include white space? I tried various combinations of throwing quotes around ?{Effect Name}, but I wasn't able to find an appropriate incantation.
1626278295
GiGs
Pro
Sheet Author
API Scripter
From the looks of it, that script uses spaces to decide where each parameter the script needs is, so you wont be able to handle white space without editing the script itself, and change the way the macro is formed.
1626278940

Edited 1626279304
Jason M.
Pro
API Scripter
So there's nothing that allows the input to specify "everything in these markers is considered one arg"? Like, with python input (and I realize it's the shell doing this, but bear with me), this... python script.py my input is bad ... has four arguments ("my", "input", "is", "bad"). However, this... python script.py "my input is bad" ... has one parameter ("my input is bad"). That's what I'm looking for. If it can't be done, handling arbitrary input is probably more work than I care to put in. Was hoping for some clever trick that I overlooked.
1626279372
The Aaron
Forum Champion
API Scripter
There are various techniques you can employ. I tend to favor using a double dash separator: !command --field arg arg --field --field arg Then split on /\s+--/ for the fields, and split each of those on spaces (or first space). You could also quote the arguments, and parse by character, but that's quite a bit harder.
1626279545
The Aaron
Forum Champion
API Scripter
There's some code for handling quoted strings in TokenMod that you could look at. You could write a very simple recursive descent parser that would split the contents... maybe I'll do that real quick when I get back to my computer. 
1626296158
Jason M.
Pro
API Scripter
The Aaron said: There are various techniques you can employ. I tend to favor using a double dash separator: !command --field arg arg --field --field arg Then split on /\s+--/ for the fields, and split each of those on spaces (or first space). You could also quote the arguments, and parse by character, but that's quite a bit harder. The --field method seems easiest to implement. In fact, I'm giving some thought to throwing together an argparse-style module to make my life easier. Thanks for the response!
1626305545
timmaugh
Pro
API Scripter
Here's a discussion of the command line that might help...