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.
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
| Thu 13 Jul 2006 03:00 PM (UTC) Amended on Thu 13 Jul 2006 03:01 PM (UTC) by Guest1
|
Message
| Hi. Can't remember how to do this or even if I can.. I'm using VB. I have an alias that I want to do three things:
set a variable
call a sub
call another sub
Having it set the var and call one sub is no problem obviously, but calling the second sub is where I'm drawing a blank.
Can the alias call two subs at once, and if so, what is the syntax I use? Usually I just use the 'edit alias' window to set it up and fill in the script textbox, but that only allows one sub to be called.. can I go to the .mcl file and just add a second 'script="subname"' line to it (I'm guessing not)? ..Or is there a different method to call subs just like with setting variables - I can either fill in the variable textbox in the 'edit alias' window and send %1, or I can send
SetVariable "varname", "%1"
instead and achieve the same thing..
Alternatively I can just call one sub from the alias, and get that one sub to call the other sub.. but unsure what the syntax is on the .vbs script to do that.
Thanks in advance for help :)
| Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #1 on Thu 13 Jul 2006 03:05 PM (UTC) |
Message
| You can call one sub, which takes care of doing everything else.
So you could have the alias call "DoMyAlias", the contents of which would be world.SetVar(blablabla), followed by CallMyFirstSub(), and finally, CallMySecondSub(). |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Guest1
USA (256 posts) |
Date
| Reply #2 on Thu 13 Jul 2006 03:18 PM (UTC) Amended on Thu 13 Jul 2006 03:23 PM (UTC) by Guest1
|
Message
| yeah cheers, ideally that's what I want to do, but what is the valid function syntax in VB? ie: I can put
SetVariable "variablename", "value"
inside a sub to set that variable, but what is the function I type to have that sub call another sub in VB (or the syntax I put in the alias itself to call the subs)? I've been looking through the MC script functions list on this site (http://www.gammon.com.au/scripts/function.php) but can't seem to spot the right one - the function that you call 'CallMyFirstSub()' etc., that is the one I want to know the correct syntax of in VB. | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #3 on Thu 13 Jul 2006 03:29 PM (UTC) |
Message
| If your sub is named MyFirstSub, then it should be sufficient to just write 'MyFirstSub' on its own line, or perhaps 'MyFirstSub()'. That's all you should have to do. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Guest1
USA (256 posts) |
Date
| Reply #4 on Thu 13 Jul 2006 04:18 PM (UTC) |
Message
| Nope doesn't seem to work in VB.. I tried a couple of ways of doing it.. first I just has the alias just call a new sub (call it subnew for now). In that subnew, I had it scripted to do the following:
sub subnew (thename, theoutput, thewildcards)
world.SetVariable "variablename", "%1"
sub1
sub2
end sub
That sets the variable ok, but errors out calling the other 2 subs. I tried also using syntax sub1() above as you suggested, but it still spat an error.
Next I tried putting all the calls inside the alias itself.. so the alias was sending to script
world.SetVariable "variablename", "%1"
sub1
sub2
that didn't work - error on line 2.. so I tried adding the () as you suggested, same problem.
..finally figured out what the problem was - it was an issue with properties / arguements and one sub needing to use wildcards, the other not.. got it to work in the end, thanks, by having the alias call the two subs in a different way each (removed irrelevant bits):
<alias
match="myalias *"
script="sub2"
send_to="12"
>
<send>
SetVariable "variablename", "%1"
sub1
</send>
</alias>
..sub1 did not require the wildcard, sub2 did. Knew there would be a way, thanks again :) | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #5 on Thu 13 Jul 2006 04:56 PM (UTC) |
Message
| Oh... if the subs need arguments, you need to call them like this: MySub arg1, arg2, ... |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Guest1
USA (256 posts) |
Date
| Reply #6 on Thu 13 Jul 2006 05:26 PM (UTC) Amended on Thu 13 Jul 2006 05:44 PM (UTC) by Guest1
|
Message
| excellent that solves a bunch of issues for me :)
cheers!
err.. ok probably messed up syntax.. if my current alias is:
<alias
match="myalias *"
script="sub2"
send_to="12"
>
<send>
SetVariable "variablename", "%1"
sub1
</send>
</alias>
and sub1 does not need the wildcard but sub2 does, I can change it to something like:
<alias
match="myalias *"
send_to="12"
>
<send>
SetVariable "variablename", "%1"
sub1
sub2 arg1
</send>
</alias>
except that line 'sub2 arg1' spits the dummy.. tried replacing it with 'sub2 arg1,' and 'sub2 %1' and a couple of others but no joy.. I figure it's just the syntax I'm not getting right.. but if not, the other way above works fine :) | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #7 on Thu 13 Jul 2006 05:46 PM (UTC) |
Message
| You need to replace arg1 with the name of the variable you're passing as an argument. So, if it's the wildcards you want to pass, you can try using 'thewildcards' or whatever the name of the wildcards variable is. (Somebody more familiar with how MUSHclient does its VBscripting might have to help out here.) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Guest1
USA (256 posts) |
Date
| Reply #8 on Thu 13 Jul 2006 05:59 PM (UTC) |
Message
| Yeah sorry, I should've said, I tried sending on that line
sub2 %1
sub2 *
sub2 (%1)
sub2 variablename
sub2 "variablename"
sub2 thewildcards
sub2 "thewildcards"
sub2 thewildcards (1)
and a few variations but no luck with any of those.. prob just a matter of syntax :/ | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #9 on Thu 13 Jul 2006 06:37 PM (UTC) |
Message
| What error message are you getting when you put in 'Sub2 %1'? |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Guest1
USA (256 posts) |
Date
| Reply #10 on Thu 13 Jul 2006 06:53 PM (UTC) |
Message
|
Wrong number of arguments or invalid property assignment: 'sub2'
Line in error:
the sub it's calling is (edited):
sub sub2 (thename, theoutput, thewildcards)
if thewildcards (1) = world.getvariable ("character") then
do some stuff
else
do some other stuff
end if
end sub
| Top |
|
Posted by
| Nexes
(65 posts) Bio
|
Date
| Reply #11 on Thu 13 Jul 2006 06:57 PM (UTC) |
Message
| That function has 3 parameters yet you are only trying to pass one argument. That's why there's an error. Hence "Wrong number of arguments" | Top |
|
Posted by
| Guest1
USA (256 posts) |
Date
| Reply #12 on Thu 13 Jul 2006 07:10 PM (UTC) |
Message
| Forgive my ignorance, but the solve this I'd do...?
Replacing that first line
(thename, theoutput, thewildcards)
with something else, or replace
thewildcards (1)
with something else? Appreciate your patience.
| Top |
|
Posted by
| Nexes
(65 posts) Bio
|
Date
| Reply #13 on Thu 13 Jul 2006 07:15 PM (UTC) |
Message
| You should call it with something like
Sub2 "" "" "%1" or something | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #14 on Thu 13 Jul 2006 07:24 PM (UTC) |
Message
| Or set the script to call "TheAliasSub" (not using send), and then:
sub TheAliasSub(thename, theoutput, thewildcards)
SetVariable "variablename", "%1"
sub1
sub2 thename, theoutput, thewildcards
end sub
sub sub2 (thename, theoutput, thewildcards)
if thewildcards (1) = world.getvariable ("character") then
do some stuff
else
do some other stuff
end if
end sub
|
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | 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.
80,390 views.
This is page 1, 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