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
➜ Calling a Sub from another Subroutine
|
Calling a Sub from another Subroutine
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Gore
(207 posts) Bio
|
| Date
| Mon 29 Mar 2004 07:15 PM (UTC) |
| Message
| Hello, I'm trying to call a sub from another sub. Here's my code:
Quote:Dim leftsword, rightsword
leftsword = World.GetVariable("varLeftSwd")
rightsword = World.GetVariable("varRightSwd")
Sub En_Aco (a,b,rapier)
Select Case LCase(rapier(1))
Case "left"
World.Send "envenom " & leftsword & " with aconite"
Case "right"
World.Send "envenom " & rightsword & " with aconite"
End Select
End Sub
Sub Keypad_1 (a,b,wildcard)
En_Aco left
En_Cur right
World.Send "dsl " & target
End Sub
<aliases>
<alias
script="keypad_1"
match="^keypad\-1$"
enabled="y"
group="offense"
regexp="y"
ignore_case="y"
keep_evaluating="y"
sequence="100"
>
</alias>
</aliases>
And I've got ctrl+1 on the keypad set up to send keypad-1 (the alias)
When I do so, I get this error:
Quote:Error number: -2146827838
Event: Execution of line 413 column 3
Description: Wrong number of arguments or invalid property assignment: 'left'
Called by: Function/Sub: keypad_1 called by alias
Reason: processing alias ""
I'm not quite exactly sure how to call a sub from another sub with arguments, any ideas? | | Top |
|
| Posted by
| Ked
Russia (524 posts) Bio
|
| Date
| Reply #1 on Mon 29 Mar 2004 08:08 PM (UTC) |
| Message
| There 2 problems here. One is that your En_Aco sub is declared to accept 3 arguments when it is called:
and you are trying to force it to accept only 1 argument:
that doesn't work in vbscript at all. The second problem is with the argument that you are trying to feed to the envenoming sub. You say:
and vbscript treats that as a variable name, but since there are no variables by that name declared anywhere in your script, the call generates an error. Try to figure out what exactly you are trying to do with the argument, judging from the En_Aco sub it should be some sort of an array, but again - no arrays to be seen anywhere. | | Top |
|
| Posted by
| Ked
Russia (524 posts) Bio
|
| Date
| Reply #2 on Mon 29 Mar 2004 08:25 PM (UTC) |
| Message
| Ok, my bad - too early in the morning and I didn't have my coffee yet. I see what you are trying to do here. Here's an amended version of your script that should work fine:
Dim leftsword, rightsword
leftsword = World.GetVariable("varLeftSwd")
rightsword = World.GetVariable("varRightSwd")
Sub En_Aco (weapon)
Select Case LCase(weapon)
Case "left"
World.Send "envenom " & leftsword & " with aconite"
Case "right"
World.Send "envenom " & rightsword & " with aconite"
End Select
End Sub
Sub Keypad_1 (a,b,wildcard)
En_Aco "left"
En_Cur "right"
World.Send "dsl " & target
End Sub
This will work as long as you have a 'target' variable defined somewhere. You'll notice that I substituted 'rapier' for 'weapon' in En_Aco sub's argument list, I thought you didn't just use rapiers so why confuse yourself :) But that's just a bullyish suggestion and should be regarded as such. | | Top |
|
| Posted by
| Ked
Russia (524 posts) Bio
|
| Date
| Reply #3 on Mon 29 Mar 2004 10:07 PM (UTC) |
| Message
| Hmm, coming back to it... You can replace the multitude of En_* subs with a single Envenom one:
Dim leftsword, rightsword
leftsword = World.GetVariable("varLeftSwd")
rightsword = World.GetVariable("varRightSwd")
Sub Envenom (weapon, venom)
Select Case LCase(weapon)
Case "left"
World.Send "envenom " & leftsword & " with " & venom
Case "right"
World.Send "envenom " & rightsword & " with " & venom
End Select
End Sub
Sub Keypad_1 (a,b,wildcard)
Envenom "left", "aconite"
Envenom "right", "curare"
World.Send "dsl " & target
End Sub
This will do the same thing, since the venom to be applied is passed to the Envenom sub along with the weapon hand, so you can do away with all the individual venom subs and use just one. | | Top |
|
| Posted by
| Gore
(207 posts) Bio
|
| Date
| Reply #4 on Tue 30 Mar 2004 03:07 AM (UTC) |
| Message
| | Ked: Thank you very much :) Is it just as fast for your third suggestion as the way I was trying to do it? | | Top |
|
| Posted by
| Ked
Russia (524 posts) Bio
|
| Date
| Reply #5 on Tue 30 Mar 2004 05:00 AM (UTC) Amended on Tue 30 Mar 2004 05:24 AM (UTC) by Ked
|
| Message
| If you are concerned about speed of execution then my third suggestion would work slower than putting it all into individual subs, but the loss in speed will become noticable only if you call the Keypad_1 sub a few hundred times in a row probably, which is not likely to ever happen. So speed is much less of an issue here than not getting lost in your script file later on is ;)
P.S. If you want an additional advice then don't prepend DSL to the envenoming commands, since that way you'll have a hard (or to be more exact - expensive) time spamming DSL. Envenom with one alias and DSL with another one. That's more buttons to press but won't waste you half a vial of venom on every balance cycle. | | Top |
|
| Posted by
| Gore
(207 posts) Bio
|
| Date
| Reply #6 on Sun 04 Apr 2004 07:54 AM (UTC) |
| Message
| | hehe, I don't spam dsl :P I'm thinking about making an auto-envenom alias, (i.e. like.. hit an alias, call a sub, or something, then every balance envenom my swords with what venoms are in the combo line next) but otherwise I just hit my macros on balance, or raze if I need to, you play achaea? | | 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.
34,102 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top