Two-variable gCLI alias?

Axaca

New member
I'm trying to make a gCLI alias that removes an item from the mall store and puts it back at a new price. Something like:
rprice [1,2] => shop take %[1]; shop put %[1] @ %[2];
Where 1 is the item name and 2 is the new price.

Is there a way to use two variables in gCLI commands, or will it require ash?

By the way, thanks dearly to the people who made gCLI a thing. It's an amazing bridge for the journey between novice and advanced KoLmafia users.
 

Bale

Minion
You need to use ash. You can set the input as a single string and then break it into pieces.

alias stuff => ashq matcher parser = create_matcher("(.+),(.+)", %%); if(parser.find()) { item it = parser.group(1).to_item(); int price = parser.group(2).to_int(); }

I left out some boring steps, like actually using the variables it and price.
 

lostcalpolydude

Developer
Staff member
You can also use split_string() and have it split on a space, comma, or whatever else. That might be simpler than using regex.
 

Bale

Minion
You can also use split_string() and have it split on a space, comma, or whatever else. That might be simpler than using regex.

I thought of that, but I figured that since some item names actually have commas in them, a greedy match for everything up to the last comma would be a better choice.
 

Winterbay

Active member
Well, you can use split_string() and define the delimiter as ";" or "--" since those are unlikely to show up in names.
 

Bale

Minion
Point to ereinion. I suppose that "--" is probably still valid, but with the way Jick names oddball items, it might not stay true. I'll stick with my easy method of finding the last comma and the simplest and best solution.
 

xKiv

Active member
You could also write stuff.ash with void main(int newprice, item itemtoreprice) { /* code here ... */ }
and call it from gCLI as "stuff (123,item name here)".
The space between script name and opening parenthesis is important.
You will get mafia's fuzzy item name matching for free, and type checking for the price.
I am not sure how well this works with commas in the name (still important if leaving them out matches a different item). I *think* mafia will parse additional commas as part of the argument (at least I think it did for me when the parameters were strings), and will use the first comma(s) to separate arguments (which is why I put the item name last and not first). But it's been a long time since I looked at that behavior (for my particular purpose, I ended up doing parameter=replace_string(parameter,":",","), but that was for maximizer strings, not item names).
 

Bale

Minion
Yes, but how can that be used as an alias?

(Commas are parsed as delimiters unless back-slash escaped.)
 

Crowther

Active member
Point to ereinion. I suppose that "--" is probably still valid, but with the way Jick names oddball items, it might not stay true. I'll stick with my easy method of finding the last comma and the simplest and best solution.
Yeah, I read that comment and thought, "As soon as you assume you can use something, Jick will use it in an item."
 

xKiv

Active member
Yes, but how can that be used as an alias?

Why do you want it to be an alias? The main difference between a %% using alias and an ash script is that invoking the script requires parentheses ...


(Commas are parsed as delimiters unless back-slash escaped.)

You must have made an incorrect assumption about what I suggested, because you are wrong (tm) (r) (c).

First, with string-typed argument:
With this in xktest.ash
Code:
void main(string a, string b) {
        print(a);
        print(b);
}
I get this in gCLI:
Code:
> xktest (bubu,booboo,baba\,bebe)
bubu
booboo baba\ bebe

And now, item-typed argument.
This is now in xktest.ash:
Code:
void main(string a, string b) {
        print(a);
        print(b);
}

And I get this in gCLI:
Code:
> xktest (bubu,maxing,relaxing)

bubu
Maxing, Relaxing

> xktest (bubu,maxing\,relaxing)

Bad item value: "maxing\"

And, for completeness ...
Code:
void main(item a, item b) {
        print(a);
        print(b);
}
gives
Code:
> xktest (maxing,relaxing,maxing,relaxing)

Maxing, Relaxing
none
> xktest (maxing\,relaxing,maxing,relaxing)

Bad item value: "maxing\"

> xktest (maxing,relaxing\,maxing,relaxing)

Bad item value: "relaxing\"

> xktest (maxing,relaxing,maxing\,relaxing)

Maxing, Relaxing
none

> xktest (maxing,maxing,relaxing,maxing)

Maxing, Relaxing
none

> xktest (maxing,maxing,relaxing)

Maxing, Relaxing
Maxing, Relaxing

So, my conclusions ...
1) I don't know what happens with the backslash, but it doesn't seem to do any escaping
2) when main has N parameters, the first N-1 commas are argument delimiters, any futher commas are part of the last argument (at least for N=2)
3) this applies before converting to any(?) type (important for string and item)
 

Theraze

Active member
Why do you want it to be an alias? The main difference between a %% using alias and an ash script is that invoking the script requires parentheses ...

*coughs* Did you actually read the OP?

I'm trying to make a gCLI alias that removes an item from the mall store and puts it back at a new price.
Is there a way to use two variables in gCLI commands, or will it require ash?

The whole goal was to try to create a two-variable gCLI alias. Yes, you can do this with an ASH script, but the whole goal was to try to see if it was possible WITHOUT creating a script.

The short answer was no. Can't do it in pure gCLI.
The slightly "ignoring the question" answer was yes, you could. Either as aliased ASH, which keeps things close to the original request, or as a script, which goes off the deep end beyond the request and full into the "way more than novice users want to think about" section.

While it's interesting to muse on the idiosyncrasies of matchers v. script requests, what was requested was an alias for a novice user working their way up. From my reading, Bale's alias meets the request, meets the requested format (first item, THEN price) for the alias, shouldn't break on any weird items, and should allow for whatever future expansions Axaca wants.
 

xKiv

Active member
*coughs* Did you actually read the OP?

By the point I saw the thread, it was already "you can't do this without any ASH", so I offered a solution that has equivalent functionality, but reinvents fewer wheels. And then I got curious how the wheels actually turn.
You never know what someone might learn.

ETA: also, if it absolutely has to be an alias ...
Code:
alias stuff => xktest (%%)

ETA: actually, if I go that far, why not something like
Code:
> alias xkstuff => ashq void fun(string it, int amt) {print(to_item(it)); print(amt);} fun(%%);

String successfully aliased.
xkstuff => ashq void fun(string it, int amt) {print(to_item(it)); print(amt);} fun(%%);

> xkstuff 'one meat',1

one million meat pancakes
1

Doesn't support item-typed parameters, and you need to use quotes, but you get full string parsing (with escapes) on any number of arguments.
 
Last edited:
Top