Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Perlscript ➜ Empty array from trigger

Empty array from trigger

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Sb   (12 posts)  Bio
Date Sat 05 Aug 2006 07:57 AM (UTC)
Message

<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?
Top

Posted by Onoitsu2   USA  (248 posts)  Bio
Date Reply #1 on Sat 05 Aug 2006 01:51 PM (UTC)

Amended on Sat 05 Aug 2006 01:53 PM (UTC) by Onoitsu2

Message
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
Top

Posted by Sb   (12 posts)  Bio
Date Reply #2 on Sun 06 Aug 2006 02:56 AM (UTC)
Message
So, if somebody who knows PERL could reply, that'd be sweet.
Top

Posted by Ked   Russia  (524 posts)  Bio
Date Reply #3 on Sun 06 Aug 2006 04:18 AM (UTC)
Message
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.
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #4 on Sun 06 Aug 2006 06:44 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #5 on Sun 06 Aug 2006 06:46 AM (UTC)
Message
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).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Dubthach   (47 posts)  Bio
Date Reply #6 on Wed 09 Aug 2006 05:17 PM (UTC)
Message
@_ 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(" ", @_).
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


24,731 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.