Trouble with parameter in alias

Bale

Minion
Could someone clue me in as to what is wrong with this?

Code:
[COLOR="#808000"]> alias tester => ash string var = "%%"; print(var); if(var == "item") {print("YAY", "green");} else abort("bad");[/COLOR]

String successfully aliased.
tester => ash string var = "%%"; print(var); if(var == "item") {print("YAY", "green");} else abort("bad");

[COLOR="#808000"]> tester item[/COLOR]

item
[COLOR="#ff0000"]bad[/COLOR]

[COLOR="#808000"]> tester nope[/COLOR]

nope
[COLOR="#ff0000"]bad[/COLOR]
I'd expect the first attempt to produce YAY, but somehow it won't match "item". Unsurprisingly, this works perfectly as an ash script, but I really want to make an alias which is bugging out because I cannot match parameters.
 

Veracity

Developer
Staff member
Try this to see what is going on:

alias tester => ash string var = "%%"; print("'"+var+"'"); if(var == "item") {print("YAY", "green");} else abort("bad");

> tester item

'item '
bad

I'll defer comment to Jason, perhaps, since I am about to move cross-country and will not have time to code for several weeks, I expect...
 

jasonharper

Developer
Use $string[%%] instead of "%%" to retrieve the parameters to an ash alias - that form trims leading/trailing whitespace.
 

Bale

Minion
Thank you both. Seeing Jason's solution I remember that this came up once before in someone else's problem and he gave the same advice. I wish I'd remembered it before he repeated himself.

I appreciate the help. It works perfectly now.

Code:
alias hipster => ashq item doodad; if($string[%%] == "stat") doodad = $item[fixed-gear bicycle]; else if($string[%%] == "item") doodad = $item[chiptune guitar]; else abort("Cannot equip that on a hipster"); cli_execute("fold "+doodad); equip(doodad);
 
Last edited:
Top