Newbie Perlscript Issues

Posted by Sb on Mon 04 Jul 2005 09:35 PM — 2 posts, 15,548 views.

#0
I'm not new to PERL, but I am new to the MUSH Client interface. I'm trying to write a script to learn languages faster (a nice beginner thing to get a good feel).

sub OnLanguageLearn {
	my ($thename, $theoutput, $wildcards) = @_;
	$Language = $world->trim ($world->GetAliasInfo ($thename, 101));
	
	if ($Language eq "") {
  		$world->send("language");
		return;
	}

	for($i = 0; $i < 10; ++$i) {
		$world->send ("language learn $Language");
	}
}

Quote:

<alias
script="OnLanguageLearn"
match="^languagelearn(.*)$"
enabled="y"
regexp="y"
ignore_case="y"
sequence="100"
>

Everytime I try, 'languagelearn common' it sends 'language' because @_ and subsequently $Langauge are always empty. What exactly am I doing wrong here? I think it's something on the alias side, but not sure.
Amended on Mon 04 Jul 2005 09:37 PM by Sb
USA #1
Why are you using the getinfo, instead of just getting the wildcard?

You probably want the first line to be:
my ($name, $output, @wildcards) = @_;
since, wildcards will/can be an array.

your alias should account for your space, ^languagelearn (.*)$ since, that'll make the wildcard be "common" in your example instead of " common".

But, the biggest problem is, your alias doesnt HAVE a name. So, you're calling getaliasinfo("",101) which returns EMPTY.

However, you could just as easily (and a couple lines smaller...ly) code the script straight into the alias.
You set the sendto box to 'script' and then you can put a script right in the aliases/triggers 'send' box. The good part is (besides not having to have a bunch of subroutines that are only used with one trigger/alias/timer, which means you have to edit/recompile your script file each time you want to add/edit one) you can use wildcard expansion.

Your script would become:
$Language = $world->trim("%1");
if ($Language eq "")
{
  $world->send("language");
}
else
{
  foreach(1..10)
  {
    $world->send("language learn $Language");
  }
}


and it will be contained within your alias, so you can delete the whole thing together, or send it to someone in one piece.