Calling script functions directly

Posted by Somec on Fri 02 Jan 2004 04:19 AM — 9 posts, 27,896 views.

#0
I have a simple perl function which I want to call directly:


sub test {
    foreach my $a (@_) {
        $world->note("$a");
    }
    $world->note("done!");
}

$world->note("hello");


This was so that I could see what was being passed to the function.

but, when I called it:

Quote:

/test 1 2 3 test test 34


MUSHClient said there was an error.

After agonizing for a bit and wondering what in my script could be the problem, I tried to put the arguments in quotes:

Quote:

/test "1 2 3 test test 34"


And that worked fine.

So, I want to know...

Am I missing a setting that only allows one argument to scripts?
Is there something I can do to avoid having to quote multiple arguments (like quoting them automatically)?
What is being done with the additional arguments on the line?
#1
Crap, I should've put this in the general forum
Australia Forum Administrator #2
I see what you mean - however the error message is from PerlScript. I suggest that the script engine must want the arguments quoted. I'm not enough of an expert on Perl to say why.
#3
Well, I'll try it out for a bit more then. Does the client support multiple scripts running from multiple languages? I have the rest of the script working in Perl, and I just need to interface it with MUSHClient somehow.

I could just make the interface in Python or something and have that call the script functions.
Australia Forum Administrator #4
Yes, you can have multiple languages if you put the script into a plugin. Each plugin can be written in a separate language.

However that shouldn't be necessary for your case. Whatever you are interfacing with the script (eg. an alias) can call the script with the arguments quoted as necessary. eg.

Alias match = foo *
Send = myscript_name "%1"
Send to = script

This would let you type "foo a b c d" (which becomes wildcard 1) which is then quoted by the alias and sent to the script. That should work OK.
#5
I had thought of doing that, but decided against it. I need some way to make the commands different from regular mud commands.

For example, I'll need a "save" command, and I can't have that as an alias and send that to the mud. Well, actually, I guess I can... I can just check to see if there are no arguments. But, that would require more aliases, more scripting, etc

Hmm... now that I think about it, that doesn't sound like a bad idea.

If I make an alias for "north" or "n" and have that alias call a script (which then sends north or n to the mud), will the function be called when a speedwalk is in progress?
#6
Ok, I've decided to just make a ".*" alias which sends %1 to the script like you've suggested. This'll make the commands different from regular mud commands. I'll just have to make a function which will call the appropriate functions.

The question on speedwalking still stands though :) I'll get around to testing it at some point, but it would be nice to just know hehe
Australia Forum Administrator #7
Ah, no. From memory, speedwalk substitution is not sent through the command processor.

If you wanted to do that you could do something like:

world.Execute world.EvaluateSpeedwalk ("ns 4e w")
#8
Ah! It's ok then, I'll just make my own :) Thanks for the help Nick