multiple (Variable) wildcards passed through alias or trigger

Posted by El_cerrito on Sat 24 May 2003 10:43 PM — 5 posts, 18,284 views.

USA #0
How do I setup an alias to call a script with a non predetermined number of wildcards? I can take the entire string of wildcards as one string and then tokenize that into individual words, but it seems like I am overdoing it then. I thought that the third argument to a script (from an alias was an array of the variables). But if I tell the alias to take three wild cards and I pass it three words it is fine. But 2 or 4 words bombs. Is there a simple way to do this or do I need to write my own sub function to figure out how many words are passed (through one wildcard) and then recurse the fxn as many times as needed (with the values). Ideally I want the script to work if I pass it one param or as many as 9 or 10.

Thanks for any help,

Tom

alias: test * * *
test values: test rhino pig mouse (works!)
test values: test rhino pig (no response)
test values: test rhino pig mouse dog (no response)

script: (below)

sub on_alias_test(strName, strThing, arrVars)

world.send "gt starting script"
dim intCounter
intCounter = 0
do while intCounter <=9
intCounter=intCounter+1
if arrvars(intcounter)<>"" then
world.send "gt var" & intCounter & " = " & arrvars(intcounter)
else
world.send "gt var" & intCounter & " is null"
end if
loop
world.send "gt made it to end of script."

end sub

sub
Australia Forum Administrator #1
Your fundamental problem here is that the triggers aren't matching because you are looking for:

test * * *

This means you want three things *separated by a space*.

Your test of "test rhino pig" is only two things, the third space is missing.

In this case the simplest thing would be to use:

test *

In the script simply use the Split function in VB to split up the wildcard (wildcard 1 in this case) to individual words, which can then be as many as you want.
USA #2
Another option is using regular expressions:

test .*( .*)?( .*)?

This would make the second and third wildcards 'optional'. however due to the way that () works, you would also need to use ltrim(arrvars(intcounter)) to remove the space that would also be captured in the wildcard.

You could also use \w* instead of .*, since that is even more specific and would only match on actual words and not extra spaces or other unwanted things. You would still need to leave the last one as .* though or you would only get:

test values: test rhino (works)
test values: test rhino pig (works)
test values: test rhino pig mouse (works)
test values: test rhino pig mouse dog (no response)

however, even in your original attempt the wildcards, had it worked, would have been:

1 - rhino
2 - pig
3 - mouse dog

So you need as many 'optional' wildcards as the maximum you expect to get, if you don't know what that maximum is, then it is still easier to do it the way Nick suggests.
USA #3
Thanks Nick, things work great now. For anyone else just getting into this I have pasted the functional version below. You call the script from an alias with anything from 1 to oodles of arguments and it will loop through and perform the command repeatedly.

sub on_alias_test(strName, strThing, arrVars)
dim arrVars2
arrVars2 = split(arrVars(1))
dim varDummy
for each varDummy in arrVars2
world.send "say " & vardummy
next
end sub

Example:
type in "test rhino pig" to the world and it will output
say rhino
say pig.

type in "test rhino pig cat dog mouse" and it will out
say rhino
say pig
say cat
say dog
say mouse
Greece #4
I just tested, and unfortunately (or maybe fortunately :p) you can't do
^test [(.*)?]+$
:)