MC message: unable to invoke script subroutine ...

Posted by Unregistered user on Sun 01 Oct 2000 12:00 AM — 6 posts, 24,379 views.

#0
I very well may be misunderstanding something very fundamental, but I get this message when a trigger tries to invoke a subroutine, testscript. However, if I enter /testscript on the MC command line, it works just fine. I have "testscript" entered in the trigger's Script: field. The vbs dll is registered. What am I not getting?

Thanks

Bruce Boyer
Australia Forum Administrator #1
The trigger calls the script with three arguments (parameters). If the script is not defined to take three you will get that error message.

Look in the exampscript.vbs file that comes with MUSHclient for examples of handling triggers.

Here is the sort of things you need to do ...


 
sub OnMyTrigger (strTriggerName, trig_line, arrWildCards)

' do something here

End Sub


#2
Well, it worked. Thanks. But, I'm puzzled as to why. Since my little test sub didn't use any of those arguments, it looked like I didn't need them, based even on examples.vbs. Perhaps something changed with 3.04? Or, with the more recent VBScript dll? In working around, I switched to JavaScript, and it worked fine without having to accept the arguments.

But it worked, so good enough. Just for completeness, and for anyone else who might stumble on this, my silly little sub was:

[code]
sub testscript
world.send "test"
end sub
[/code]

That failed, but:

[code]
sub testscript (a, b, c)
world.send "test"
end sub
[/code]

succeeded.

Thanks again. I am enjoying MUSHclient

Bruce
Australia Forum Administrator #3
It worked when you tested it because your sub required no arguments, and when you tested it you supplied none.

Most languages do not allow you to call a subroutine with the incorrect number of parameters.

As to why JavaScript worked, it must have set the missing arguments to "null" or something like that.
#4
I'm getting the same error message, but I have all the correct parameters. I have a script set up to automatically practice spells, and so far it's worked great. I was trying to add in another bit so I'd automatically sleep for a certain amount of time, then automatically wake back up and start practicing again. The subroutine I have to start practicing is as follows:


sub beginprac (strAliasName, strOutput, arrWildCards)
world.addtrigger "practicer", "Saving...$", "c slow self\nc slow self\nc slow self\nc slow self\nsave", 33, 0, 0, "", ""
world.addtrigger "hungry", "(You are hungry.$|You are thirsty.$)", "", 33, 0, 0, "", "imhungry0"
world.addtrigger "outomana", "You don't have enough mana.$", "", 33, 0, 0, "", "endprac"
world.send "save"
end sub


When I call it with an alias, it works fine. However, with my end practice subroutine, here:


sub endprac (strAliasName, strOutput, arrWildCards)
world.deletetrigger "practicer"
world.deletetrigger "hungry"
world.deletetrigger "outomana"
world.addtimer "sleep_timer", 0, 1, 30, "wake", 5, "beginprac"
world.send "where"
end sub


It errors when the timer pops up. The command "wake" still goes through, but the "unable to invoke script subroutine" pops up and MUSHclient crashes (last time it crashed, I had to restart my whole system).

Also, in another part of my script, I have triggers call scripts with no trouble, and they're in the same format as the one I'm trying to get to work.

Any assistance would be greatly appreciated.

Thanks,
Riven
Australia Forum Administrator #5
Triggers and aliases are called with three arguments, timers with one, like this:


sub OnTimer (strTimerName)
  world.note "Timer has fired!"
end sub



Thus, you cannot call "beginprac" from a timer, which is what you are doing.

What you can do to work around this is to put the code you currently have into a separate routine (eg. Start_Practice) and call that from both the alias and the timer.

eg.




sub Start_Practice (strName)
world.addtrigger "practicer", "Saving...$", "c slow self\nc slow self\nc slow self\nc slow self\nsave", 33, 0, 0, "", ""
world.addtrigger "hungry", "(You are hungry.$|You are thirsty.$)", "", 33, 0, 0, "", "imhungry0"
world.addtrigger "outomana", "You don't have enough mana.$", "", 33, 0, 0, "", "endprac"
world.send "save"
end sub

sub beginprac (strAliasName, strOutput, arrWildCards)
  call Start_Practice (strAliasName)
end sub

sub endprac (strAliasName, strOutput, arrWildCards)
world.deletetrigger "practicer"
world.deletetrigger "hungry"
world.deletetrigger "outomana"
world.addtimer "sleep_timer", 0, 1, 30, "wake", 5, "Start_Practice"
world.send "where"
end sub