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
➜ Calling a Sub from a sub
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| David B
USA (80 posts) Bio
|
Date
| Tue 11 Mar 2003 12:56 PM (UTC) |
Message
| Is there anyway to call a second Subroutine, from within a Subroutine?
sub whaterver(name, line, wilds)
<insert random code>
if yadda yadda = blah then
callsub (yadda)
else
yadda yadda
end if
endsub |
My code(with a LOT of Nicks help) to fame:
sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
| Top |
|
Posted by
| Magnum
Canada (580 posts) Bio
|
Date
| Reply #1 on Tue 11 Mar 2003 01:17 PM (UTC) Amended on Tue 11 Mar 2003 01:28 PM (UTC) by Magnum
|
Message
| Visual Basic Scripting Edition Language Reference
--------------------------------------------------------------------------------
Call Statement
Transfers control to a Sub or Function procedure.
[Call] name [argumentlist]
Arguments
Call
Optional keyword. If specified, you must enclose argumentlist in parentheses. For example:
Call MyProc(0)
name
Required. Name of the procedure to call.
argumentlist
Optional. Comma-delimited list of variables, arrays, or expressions to pass to the procedure.
Remarks
You are not required to use the Call keyword when calling a procedure. However, if you use the Call keyword to call a procedure that requires arguments, argumentlist must be enclosed in parentheses. If you omit the Call keyword, you also must omit the parentheses around argumentlist. If you use either Call syntax to call any intrinsic or user-defined function, the function's return value is discarded.
Call MyFunction("Hello World")
Function MyFunction(text)
MsgBox text
End Function
Requirements
Version 1
--------------------------------------------------------------------------------
©2000 Microsoft Corporation. All rights reserved.
|
Get my plugins here: http://www.magnumsworld.com/muds/
Constantly proving I don't know what I am doing...
Magnum. | Top |
|
Posted by
| David B
USA (80 posts) Bio
|
Date
| Reply #2 on Tue 11 Mar 2003 02:11 PM (UTC) |
Message
| So if I get this straight
I can do a subroutine and depending if a variable is X or Y I could call an external subroutine. |
My code(with a LOT of Nicks help) to fame:
sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
| Top |
|
Posted by
| Shadowfyr
USA (1,791 posts) Bio
|
Date
| Reply #3 on Tue 11 Mar 2003 06:06 PM (UTC) |
Message
| In short yes. Note a few things however:
1. Using 'call' is always prefered for 'sub' types. Without it both pure Visual Basic and VBScript will do odd things in some cases. This is because a sub called without the 'call' command is treated different that one that is called that way. Better safe than confused and even the description of why and what happens when you do it the wrong way confuses me. ;)
2. There is a difference between 'function' and 'sub'. Technically 'function' is used to return a value after a call, it only uses the 'call' command it you don't care what is returned (which is the case with most Mushclient's own script commands like world.note, where if it doesn't work, it tends to be pretty obvious. Example:
function Test(blah)
if blah = 1 then
Test = blah
world.note blah
end if
end function
sub Test(blah)
if blah = 1 then
world.note blah
end if
end sub
You could call these like:
Variable = Test(MyValue)
and
call Test(MyValue)
The first version would return nothing if 'blah' was anything except 1, or 1 if it is, and place the result in your variable. This is convenient for things like a color calculator I use that requires the same large batch of code to be called up to 12 times in the same script and returns a HTML color string. The second version just performs a task and returns without any result. Unless you have to return some value or you need to return an error so that you know if something worked, you probably won't need the 'Variable = sub' version.
3. The 'name' of the variable does not need to be the same in the sub declaration as in the call. VBScript only cares that you pass the correct number and real languages that allow you to specifically tell it the type, like 'integer' or 'string', only care that what you send the sub or function is the same type and in the right order. This lets you give the variable a name that makes sense for that subroutine, but may be called something else in the one calling it. Example:
sub List
for count = 0 to 19
call Show(Weapons(count))
next
end sub
sub Show(Weapon)
world.colournote "Purple","Black",Weapon
end sub
This is a simple example, but the idea is that since you are only dealing with one 'weapon' at a time in Show, it makes sense to use that name there, even though the call uses an array called 'Weapons'. | 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.
15,017 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top