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
➜ General
➜ alias calls 2 subs and sets var
alias calls 2 subs and sets var
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1
2 3
Posted by
| Guest1
USA (256 posts) |
Date
| Reply #15 on Thu 13 Jul 2006 07:24 PM (UTC) |
Message
| tried using sub2 "" "" "%1"
Expected end of statement
Line in error:
sub2 "" "" "value"
tried with 1 and 2 less "" sets before, and even tried an extra "" after, none worked :/ | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #16 on Thu 13 Jul 2006 07:25 PM (UTC) |
Message
| You need commas between arguments. But see the post I put up while you wrote yours. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Guest1
USA (256 posts) |
Date
| Reply #17 on Thu 13 Jul 2006 07:43 PM (UTC) |
Message
| ok.. I tried what you said first and created a new sub:
sub TheAliasSub(thename, theoutput, thewildcards)
SetVariable "variablename", "%1"
sub1
sub2 thename, theoutput, thewildcards
end sub
and while it solved the issue I had, it created a new issue as it set the value of the variable physically to %1 rather than the value I entered on the alias.. hehe
so.. I took out the SetVariable "variablename", "%1" from the sub above and put it back into the alias itself, so the alias sets the variable and calls the sub above (less the set.var line).. that worked :) However I'm trying to cut down the size of my 5-year-old script rather than add additional subs, so I'll try with commas as you said..
..and nope, using
sub2 "", "", "%1"
spat an error
Type mismatch: 'thewildcards'
Line in error:
fun huh. Must be a way this works without writing additional subs. | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #18 on Thu 13 Jul 2006 08:07 PM (UTC) |
Message
| You probably don't want the quotes around %1. Try just %1, without the quotation marks.
The other problem is that %1 is a string, not an array of wildcards, whereas the sub expects the whole wildcard array.
If you only care about the first one, you could adjust sub2 to take only one argument, a single string, and remove the first two arguments (which you don't appear to be using). Then, you could call sub2 in the <send> block passing in %1 as the sole argument. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Guest1
USA (256 posts) |
Date
| Reply #19 on Thu 13 Jul 2006 08:51 PM (UTC) |
Message
| Still get a Type mismatch: 'thewildcards' error without the quotes around the %1 unfortunately.
Yes I only care about the first (and only) wildcard as it's an alias I'm initially using to send it rather than a trigger with a possible bunch of variables. When you say about adjusting the number of arguments and the sub, I take it you mean that the alias should just be sending 'sub2 %1' and then the sub itself should be written instead of:
sub sub2 (thename, theoutput, thewildcards)
if thewildcards (1) = world.getvariable ("character") then
do some stuff
else
do some other stuff
end if
end sub
I should amend it to:
sub sub2 (thewildcards)
if thewildcards = world.getvariable ("character") then
do some stuff
else
do some other stuff
end if
end sub
..? Now although that doesn't spit an error, it also has stopped matching on that if statement.. (I tried writing wildcard without the 's' in both cases above too - no joy).. Probably my lack of knowledge in syntax is the problem now.. | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #20 on Thu 13 Jul 2006 08:56 PM (UTC) |
Message
| Variable names aren't really important. You could call them flibberfloop or var12345; it doesn't matter. They're just names that make it easier for us humans to know what the variable is supposed to refer to.
Anyhow, you could try doing something like this in sub2, before the if check:
World.note %1
World.note world.getvariable ("character")
That could help you see what the two things actually are. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Guest1
USA (256 posts) |
Date
| Reply #21 on Thu 13 Jul 2006 09:04 PM (UTC) Amended on Thu 13 Jul 2006 09:10 PM (UTC) by Guest1
|
Message
| well the variable is getting set ok (that is set direct from the alias), but '%1' as an actual value is being sent to the sub, not the wildcard...
It all works fine using this setup as the alias:
<alias
match="myalias *"
script="sub2"
send_to="12"
>
<send>
SetVariable "variablename", "%1"
sub1
</send>
</alias>
but only because sub1 does not require the wildcard, onlt sub2 does.. but I'm trying to get sub2 out of the script field where it is in the above example, and put it into the send field, because in another alias I will want both sub1 and sub2 to require that wildcard, and as far as I know, you can't put two subs in that script field on the 'edit alias' window. | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #22 on Thu 13 Jul 2006 09:18 PM (UTC) |
Message
| So, you're saying that when you World.note %1, you get a literal %1, not the first match? And that happens whether you do it in script, send, or sub2? |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Guest1
USA (256 posts) |
Date
| Reply #23 on Thu 13 Jul 2006 09:28 PM (UTC) |
Message
| if I put the world.note "%1" in the alias it shows the value of the match correctly.. if I put the world.note it in the sub2 on my vbs script, I get %1 as the value.. so what is getting sent through to sub2 from the alias when I use
sub2 %1
in the alias send field is not the wildcard, but %1.. | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #24 on Thu 13 Jul 2006 09:32 PM (UTC) |
Message
| Oh... in the sub2 subroutine, you have to use the name of the argument, not %1... But, you want to use %1 in the alias field.
Do you know what subroutines and arguments are? It seems like it might be a good time to go back to basics a bit. :) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #25 on Thu 13 Jul 2006 10:07 PM (UTC) |
Message
| You are confusing two methods here:
<alias
match="myalias *"
script="sub2"
send_to="12"
>
<send>
SetVariable "variablename", "%1"
sub1
</send>
</alias>
The part between <send> and </send> (ie. the contents of the "send" box) are what has the %1 substitution done. Your call of sub1 cannot know the wildcards, as you didn't pass them down.
Your call of sub2 knows the wildcards, but they are in the arguments that MUSHclient supplies.
i.e.
Sub sub2 (name, line, wildcards)
Note wildcards (2)
End Sub
Having said that, there is a way for all 3 to get wildcards in a consistent way, and that is to use GetTriggerWildcard.
That returns the named of numbered wildcard of the most recent matching trigger. You can use that in send to script, or the subs called directly or indirectly. For example:
<triggers>
<trigger
enabled="y"
match="The (.*) of"
name="myname"
regexp="y"
send_to="12"
sequence="100"
>
<send>Note (GetTriggerWildcard ("myname", 1))</send>
</trigger>
</triggers>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Guest1
USA (256 posts) |
Date
| Reply #26 on Thu 13 Jul 2006 10:13 PM (UTC) |
Message
| Heh.. I feel like I'm going in circles here. Clearly I need assistance - that's why I'm posting here :) I'm rewriting a script I wrote 5 years ago, and haven't dealt with it again in any great detail since then ..until now.
Ok to make it easy for me see if you can solve this. I have an alias of 'myalias *' When I type a command of 'myalias Joe', I want that alias to set a variable called 'name' to the name 'Joe', and also call two sub routines, named sub1 and sub2, which are included among many many others sitting on my script.vbs file.
Presently I have been able to set it up myself without issue when only one of the subs requires that wildcard of 'Joe', because the one that needs the wildcard I place in the script field of the alias, like so:
<alias
match="myalias *"
script="sub2"
send_to="12"
>
<send>
SetVariable "name", "%1"
sub1
</send>
</alias>
along with the subs like so.. first the one that needs the wildcard:
sub sub2 (thename, theoutput, thewildcards)
if thewildcards (1) = world.getvariable ("character") then
do some stuff
else
do some other stuff
end if
end sub
and then the sub that doesn't need the wildcard:
sub sub1
do some stuff
end sub
However, if I needed BOTH subs to use that wildcard, that's where I get stuck. I can't both both sub1 and sub2 in that script box on the alias, so I have to figure how to get the send box to call a subroutine that also requires a wildcard (in this example, Joe), without writing another subroutine to call the existing subroutines sub1 and sub2.
Effectively I would like to move that sub2 out of the 'script' field on the alias and put it in the 'send' field of the alias.. but 'sub1 %1' and many other variations as detailed over the last page and a half don't work - the best result I got was that it all worked without error, but what got sent to sub2 was the value '%1' instead of 'Joe'.. if anyone can actually spell it out for me I would be very grateful, and will be able to learn from it :)
Thanks. | Top |
|
Posted by
| Guest1
USA (256 posts) |
Date
| Reply #27 on Thu 13 Jul 2006 10:24 PM (UTC) Amended on Thu 13 Jul 2006 10:32 PM (UTC) by Guest1
|
Message
| Oops just saw your comment Nick, posted while I was writing mine. Thanks.
So really the bottom line is I can't send a call to a sub that includes a wildcard directly from the alias 'send' field the way I was trying to? I can only use the 'script' field of the alias to do that, thus am limited to one sub per alias that requires the wildcard (although multiple subs that don't require a wildcard is not a problem).. which is what I actually thought from the start but was trying to find out one way or the other for sure, hehehe.
The way around you said is to use GetTriggerWildcard which involves an additional trigger. Another method actually worked back here too, which was to use the 'script' field to call a sub that would thus also see the wildcard value, and then have that sub call the other subs that want to use that wildcard value.
Anyway I think I have my answer - I can't really get one alias to directly call multiple subs where more than one of those subs requires a wildcard value.. unless I create an additional sub or trigger to handle it.
| Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #28 on Thu 13 Jul 2006 10:28 PM (UTC) Amended on Thu 13 Jul 2006 10:29 PM (UTC) by Nick Gammon
|
Message
|
Quote:
I can't really get one alias to directly call multiple subs where more than one of those subs requires a wildcard value..
Well, you can because the caller knows the wildcards.
eg.
SetVariable "variablename", "%1"
sub1 "%2", "%3"
Here you are calling sub2 (from the trigger itself) and in the "send to script" are calling sub1, passing down wildcards 2 and 3.
Also check out:
http://www.gammon.com.au/scripts/doc.php?function=GetTriggerInfo
Using that you can get the wildcards for any recent trigger, so the sub could use that. Of course, as well as:
http://www.gammon.com.au/scripts/doc.php?function=GetTriggerWildcard
So, you really have many ways of solving this problem. :) |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Guest1
USA (256 posts) |
Date
| Reply #29 on Thu 13 Jul 2006 10:43 PM (UTC) |
Message
| Yup thanks, just other ways of doing it than most people here thought :)
I wonder if that could be looked at in some future release though (if it's feasible) to be able to just write an alias (not a trigger) of, for example,
<alias
match="my * has * so back off."
send_to="12"
>
<send>
sub1 %1
sub2 %1
sub3 %2
</send>
</alias>
If I then type in the command line 'my girlfriend has rabies so back off.', sub1 and sub2 would be called and use the wildcard 'girlfriend', and sub3 would be called using the wildcard 'rabies'.. :)
| 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.
89,250 views.
This is page 2, subject is 3 pages long:
1
2 3
It is now over 60 days since the last post. This thread is closed.
Refresh page
top