[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Perlscript
. . -> [Subject]  Empty array from trigger
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Empty array from trigger

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


Posted by Sb   (12 posts)  [Biography] 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?
[Go to top] top

Posted by Onoitsu2   USA  (248 posts)  [Biography] 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
[Go to top] top

Posted by Sb   (12 posts)  [Biography] 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.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (21,405 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (21,405 posts)  [Biography] 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
[Go to top] top

Posted by Dubthach   (47 posts)  [Biography] 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(" ", @_).
[Go to top] 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.


6,709 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]