Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ VBscript
➜ multiple (Variable) wildcards passed through alias or trigger
|
multiple (Variable) wildcards passed through alias or trigger
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| El_cerrito
USA (5 posts) Bio
|
| Date
| Sat 24 May 2003 10:43 PM (UTC) |
| Message
| 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 | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Sat 24 May 2003 10:57 PM (UTC) |
| Message
| 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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Shadowfyr
USA (1,792 posts) Bio
|
| Date
| Reply #2 on Sat 24 May 2003 11:14 PM (UTC) |
| Message
| 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. | | Top |
|
| Posted by
| El_cerrito
USA (5 posts) Bio
|
| Date
| Reply #3 on Sat 24 May 2003 11:42 PM (UTC) |
| Message
| 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
| | Top |
|
| Posted by
| Poromenos
Greece (1,037 posts) Bio
|
| Date
| Reply #4 on Sun 25 May 2003 12:54 AM (UTC) |
| Message
| I just tested, and unfortunately (or maybe fortunately :p) you can't do
^test [(.*)?]+$
:) |
Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it! | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
17,497 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top