Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11

Thread: CLI Variable Input

  1. #1
    Senior Member
    Join Date
    Apr 2018
    Posts
    133

    Default CLI Variable Input

    Is it possible to run a script with multiple input variables without using the dialog box to enter values each time? I’ve been trying to run Veracity’s MMG script without having to type numbers manually each run, but it will only set the first variable in main. Any other numbers in the CLI are disregarded.

    For example, “mmg2 2000” and “mmg2 2000 2 5 5” will do the exact same thing, asking for the last three int variables it needs to run.

    Am I missing something, or is this a real limitation of KoLmafia? Do I have to rewrite the script to accept one variable and extract four values from it to get this to behave that way?

  2. #2
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    11,427

    Default

    Try "mmg2 (2000,2,5,5)".

    Note the space between the script name and the parenthesized list of comma-separated arguments.

  3. #3
    Senior Member
    Join Date
    Apr 2018
    Posts
    133

    Default

    Thank you, that’s exactly what I was looking for.

    The syntax is rather bizarre, though. Is that documented anywhere I missed?

  4. #4
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    11,427

    Default

    I wouldn't know. I looked at the source code. Who reads documentation?

    It would be less bizarre, to my eye, if you didn't need that space. It would then, essentially, look like a call to the main() function of the specified script.

  5. #5
    Senior Member
    Join Date
    Apr 2009
    Posts
    1,814

    Default

    I believe it's because CLI does word splitting first, so "mmg(2000,2,2,5)" would be trying to call a script or macro *named* "mmg(2000,2,2,5)" (with no parameters)?

  6. #6

    Default

    It seems reasonable to decide that script names are not allowed to have parentheses in them (I don't recall ever seeing a script name with parentheses, so probably no one would notice), and to adjust parsing appropriately. If someone was motivated enough to make that change.

  7. #7
    Senior Member
    Join Date
    Apr 2018
    Posts
    133

    Default

    I sort of just assume everything uses POSIX shell syntax until I learn otherwise. If you want to change the syntax, I recommend using that as a model.

  8. #8
    Senior Member
    Join Date
    Apr 2009
    Posts
    1,814

    Default

    I sort of just assume everything uses POSIX shell syntax until I learn otherwise. If you want to change the syntax, I recommend using that as a model.
    Originally Posted by Saklad5 View Post
    In the CLI, that would probably change semantics of aliases (or more). Which could break old code.

    See the PriceAdvisor thread (currently at https://kolmafia.us/showthread.php?31...l=1#post147536 ) for benefits of not breaking old code.

  9. #9
    Senior Member
    Join Date
    Apr 2018
    Posts
    133

    Default

    Of course. I’m just saying that if you are going to change it anyway, you should change it to match the POSIX shell.

    How exactly do aliases work, anyway? Would they be incompatible?

  10. #10
    Senior Member
    Join Date
    Apr 2009
    Posts
    1,814

    Default

    I think X => Y just does a .replaceAll("X","Y"), everywhere on the line, even in the middle of words. This is why using "parametrized" aliases is recommended: if you use %% in the replacement, mafia will only replace X at the beginning of a line.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •