grrrr. can someone please tell me why I get an error message on this plugin?

Posted by Nobody on Thu 18 May 2006 09:36 AM — 7 posts, 31,343 views.

#0
I'm trying to make it myself, I setup the triggers in mushclient, exported them to the plugin file, and now I'm writing the script that I want it to use in the xml file.

In the plugin area, I have
language="PerlScript"

In the trigger area:
<trigger
enabled="y"
group="ticktimer"
name="prompt"
match="^(.*?)hp (.*?)mv (.*?)xp (.*?)$"
omit_from_output="y"
regexp="y"
script="handle_prompt"
sequence="100"
>

In the script area I have:
<script>
<![CDATA[

def handle_prompt()
{
$args = shift;
$world->Note("DEBUG: $args");

}
]]>

</script>

When I load (try to load) the plugin, I get:
syntax error at (eval 2) line 2, near ")
{"
syntax error
Line in error:

followed by another popup saying:
You have not specified a script file name:

The trigger (prompt) subroutine named "handle_prompt" could not be found.

Why can't the subroutine be found? IT'S RIGHT THERE. I explicitly define it right there!!!

Someone please explain how to get plugins to work with scripts?
Australia Forum Administrator #1
I'm not a Perl expert, but are you sure you have the right syntax? My exampscript.pl file, which ships with MUSHclient, defines subroutines a bit differently to that, for example:


# ------------------------------------------
# Example showing a script called by a timer
# -------------------------------------------
sub OnTimer
{
my ($strTimerName) = @_;

$world->note ("Timer $strTimerName has fired!");
}	# end of OnTimer 

USA #2
There are two problems. For starters you shouldn't use def, you should be using sub, as Nick said.

Second, you declared it with a no-argument prototype (by adding the () at the end). Either you should declare it with an "open" prototype (with just sub FunctionName) or you should use the correct prototype. My advice is to not use prototypes unless you have a fairly good reason to.

Also, by doing $args = shift, you will only be getting the first argument into $args. If you want the whole array of arguments, you should do @args = @_. Or, do like what Nick posted. Or yet again, $arg1 = shift; $arg2 = shift; etc.
Australia Forum Administrator #3
There is a Perlscript plugin:

http://www.mushclient.com/plugins/Perlscript_Version.xml

This simply shows the current version of Perlscript, however as a fully-working plugin written in Perlscript you should be able to see the syntax of getting a plugin working in Perl.

Quote:

I get: syntax error at (eval 2) line 2,

...

Why can't the subroutine be found? IT'S RIGHT THERE. I explicitly define it right there!!!


If you get a syntax error, then the module won't be found, as it didn't compile. Fix the syntax error first.
#4
My god how embarassing. How did I get that syntax screwed up? In my defense, I was tired and so on but still... what language is 'sub' from? Clearly I was getting all confused. This is the trouble with learning 4 scripting languages at once!

No doubt I'll have many many more questions in the future, I just hope that I get the basic language syntax correct :\
USA #5
Sub is a lua or Perl syntax, where is def is a python syntax.
But asking questions is how you learn! So feel free to ask em here. I've always found the peoples on this forum very helpful and considerate, so long as you yourself are respectful, and courteous.

-- Rakon

**EDIT**
Can't spell for the life of me.
Amended on Fri 19 May 2006 08:19 AM by Rakon
USA #6
Actually, Lua uses 'function', not 'sub' -- at least it does as of 5.1 and I believe 5.0 as well. Perl definitely uses at least 'sub'. And just for kicks, Lisp uses something in between def and function: 'defun'. :)