Empty array from trigger

Posted by Sb on Sat 05 Aug 2006 07:57 AM — 7 posts, 34,000 views.

#0

<triggers
   muclient_version="3.73"
   world_file_version="15"
   date_saved="2006-08-05 03:54:26"
  >
  <trigger
   enabled="y"
   match="^STR\: (.*?)  INT\: (.*?)  WIS\: (.*?)  DEX\: (.*?)  CON\: (.*?)  CHA\: (.*?)$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>OnStats</send>
  </trigger>
</triggers>


and the function is...


sub OnStats
{
	$world->Note("Main Array: ".@_);
}


Just to debug, it prints the array size... it is always 0 even though the trigger matches. Any insight?
USA #1
I do not program in that particular language, but this does not look right...

sub OnStats

should it not be something like...

sub OnStats(sName,sLine,wildcards)

then from the wildcards variable that is passed in you should derive the array...

but since you are not having the (sName,sLine,wildcards)
there you are basically denying the passing in of the matched values. So it IS matching, just NOT saying WHAT was matched.

I may just be talking out of my ass, as like I said I do not program in that language, I use LUA, and VBScript (Prefer LUA.... LUA ROCKS!!!)

Hope that corrects the issue,
Onoitsu2
Amended on Sat 05 Aug 2006 01:53 PM by Onoitsu2
#2
So, if somebody who knows PERL could reply, that'd be sweet.
Russia #3
Don't know Perl either, but I think your problem is in the fact that you call the on OnStats sub via send-to-scripting, without passing any arguments. Mushclient itself doesn't pass anything either, so since no arguments are passed - the args list is going to be empty.
Australia Forum Administrator #4
I would look at the exampscript.pl file that ships with MUSHclient for examples of using the arguments in Perl.

For example:


sub OnStats
{
my ($strTriggerName, $trig_line, $wildcards) = @_;

$iHP = $world->GetTriggerInfo ($strTriggerName, 101);
$iMana = $world->GetTriggerInfo ($strTriggerName, 102);
$iMV = $world->GetTriggerInfo ($strTriggerName, 103);

$world->Note ("Your HP are $iHP");
$world->Note ("Your Mana is $iMana");
$world->Note ("Your movement points are $iMV");

}	# end of OnStats 



Note the first line in the sub which takes the @_ argument and converts it into the trigger name, matching line, and wildcards. Let me know if that doesn't work.
Australia Forum Administrator #5
And judging by the way I implemented that, I was having trouble getting the wildcards array in Perl. :)

Since that was written there is a new script function GetTriggerWildcard, see this page:

http://www.gammon.com.au/scripts/doc.php?function=GetTriggerWildcard

That lets you recall any of the wildcards for a trigger. (A similar thing exists for aliases).
#6
@_ is an entire array named _. To print an item in an array you must refer to it as a scalar, which is $_[0] or $_[1] etc. If you wanted to concatenate all members of the array together, use something like join(" ", @_).