Errors using simple PerlScript functions in MUclient

Posted by 1of10 on Thu 27 Feb 2003 06:53 PM — 15 posts, 58,283 views.

Canada #0
I've never had any other problems like these with Perl/PerlScript. I'm using the latest MUclient and PerlScript (from ActiveState).




I have a ping subroutine that I use to ping the sites I connect to. It reports the ping time or failure in the status bar. This routine worked flawlessly when I was using the standard Net::Ping package. I recently installed the Time::HiRes package, which provides the ability to use milliseconds in Perl. To activate this in the ping package, I use the following:

$p = Net::Ping->new("icmp", , 8);
$p->hires(1);  # enable milliseconds via Time::HiRes

When I try to call the subroutine to ping the site, with hires active, MUclient returns an error dialog with the following details:

Error number: -2147467259
Event:        Execution of line 1 column 0
Description:  Internal Error
Line in error: 
Called by:    Immediate execution





I have a subroutine that spews out a word repeated several times on one line, each instance with a different colour code (this is for a talker system that supports colour codes). The idea is to have a line like this:

Hello!Hello!Hello!Hello!Hello!

Each instance of "Hello!" is coloured differently. The script randomly picks a colour set for each instance. However, MUclient does not like the rand() function of PerlScript! I have to put the rand() function into a seprate script, converted to a .BAT file, then call it from within the MUclient script. (This method is REALLY slow to process!!) If I try to use rand() within a MUclient script, I receive the following error dialog:

Error number: -2147467259
Event:        Execution of line 1 column 0
Description:  Internal Error
Called by:    Function/Sub: doRainbow called by alias
              Reason: processing alias "rainbow"





Initially I thought these errors might be caused by an outdated version of ActivePerl. But, after upgrading to the latest version, these errors still happen.
Australia Forum Administrator #1
Quote:

Each instance of "Hello!" is coloured differently. The script randomly picks a colour set for each instance. However, MUclient does not like the rand() function of PerlScript!


It would help to show the actual script. I can't debug script problems when I only see the error message and not the script that causes it.

There is no way that MUSHclient can not "like" individual parts of a language like Perlscript. It passes the whole script down to the script engine. It doesn't get a say in which words the script engine will process or not process.
Canada #2
I don't see how this will matter much, but here is the subroutine (including all the spammy codes array, best viewed in fixed width font with no word wrap):

sub doRainbow {
	my(@codes)=(
		'~BK~FR','~BK~FG','~BK~FY','~BK~FB','~BK~FM','~BK~FT','~BK~FW',
		'~BK~OL~FR','~BK~OL~FG','~BK~OL~FY','~BK~OL~FB','~BK~OL~FM','~BK~OL~FT','~BK~OL~FW','~BK~OL~FK',
#		         '~BR~FG','~BR~FY','~BR~FB','~BR~FM','~BR~FT','~BR~FW','~BR~FK',
#		            '~BR~OL~FG','~BR~OL~FY','~BR~OL~FB','~BR~OL~FM','~BR~OL~FT','~BR~OL~FW','~BR~OL~FK',
		'~BG~FR',                  '~BG~FB','~BG~FM',         '~BG~FW','~BG~FK',
		'~BG~OL~FR',            '~BG~OL~FY','~BG~OL~FB','~BG~OL~FM','~BG~OL~FT','~BG~OL~FW',
#		'~BY~FR','~BY~FG',         '~BY~FB','~BY~FM','~BY~FT','~BY~FW','~BY~FK',
#		'~BY~OL~FR','~BY~OL~FG',            '~BY~OL~FB','~BY~OL~FM','~BY~OL~FT','~BY~OL~FW','~BY~OL~FK',
		'~BB~FR','~BB~FG','~BB~FY',         '~BB~FM','~BB~FT','~BB~FW','~BB~FK',
		'~BB~OL~FR','~BB~OL~FG','~BB~OL~FY',            '~BB~OL~FM','~BB~OL~FT','~BB~OL~FW','~BB~OL~FK',
#		'~BM~FR','~BM~FG','~BM~FY','~BM~FB',         '~BM~FT','~BM~FW','~BM~FK',
#		'~BM~OL~FR','~BM~OL~FG','~BM~OL~FY','~BM~OL~FB',            '~BM~OL~FT','~BM~OL~FW','~BM~OL~FK',
#		'~BT~FR','~BT~FG','~BT~FY','~BT~FB','~BT~FM',         '~BT~FW','~BT~FK',
#		'~BT~OL~FR','~BT~OL~FG','~BT~OL~FY','~BT~OL~FB','~BT~OL~FM',            '~BT~OL~FW','~BT~OL~FK',
#		'~BW~FR','~BW~FG','~BW~FY','~BW~FB','~BW~FM','~BW~FT',         '~BW~FK',
#		'~BW~OL~FR','~BW~OL~FG','~BW~OL~FY','~BW~OL~FB','~BW~OL~FM','~BW~OL~FT',            '~BW~OL~FK',
		'*');
	my(@done)=(0);
	my($n,$r,$alldone,$out)=(0,0,0,'');
	for ($n=0; $n<$#codes; $n++) { $done[$n]=0; }
	my($word)=@{$_[2]}[0];
	chomp($word);
	srand;
	until ($alldone) {
		#$r=(int(qx(c:/bin/rnd $#codes)));
		$r=(int(rand($#codes)));  # <-- This line!
		if (!$done[$r]) {
			$done[$r]=1;
			$out.="$codes[$r]$word\~RS";
		}
		$alldone=1 if (join('',@done) !~ m/0/g);
	}
	$world->send($out);
}

The line marked with <-- This line! is what causes the error. The line above that calls c:/bin/rnd is the external script (as a .BAT file) that uses the same rand() function. If I use rand() inside a MUclient script, MUclient throws an error. If I use it externally, the subroutine takes forever to process but does complete successfully.
Amended on Sat 01 Mar 2003 07:15 AM by 1of10
Australia Forum Administrator #3
I think you have some straightforward bugs in your code, nothing to do with the MUSHclient program.

I am not a Perl expert, but for a start I think this line is wrong:


for ($n=0; $n<$#codes; $n++) { $done[$n]=0; }


According to my Perl book the sequence $# is the "number output format". Using it in this context doesn't make sense. I think you mean to get the number of items in @codes, which is @codes. So it should read:


for ($n=0; $n<@codes; $n++) { $done[$n]=0; }


Much the same applies to the line causing you grief:


$r=(int(rand($#codes)));  # <-- This line!


I think you mean:


$r=(int(rand(@codes)));  


I tried using "rand" in an "immediate" window in MUSHclient - it worked perfectly, so there is no problem in using rand as such.

Amended on Sun 02 Mar 2003 12:09 AM by Nick Gammon
USA #4
Actually Nick.. I nosed about on this too and it seems that in the case where you do $#Variable with an array it is 'supposed' to return the number of elements it contains. However there is a note in the same site referring to some odd situations where declaring an array as 'my(Variable) =' will generate an error, due to the variable being 'undeclared', if you try to use it by itself. The correct way is to not use 'my'. Then again... I know even less about Perl than you do, so I can't be sure an considering the wonderfully cryptic syntax it uses I don't plan to become an expert any time soon. ;) lol
Amended on Sun 02 Mar 2003 05:05 AM by Shadowfyr
Canada #5
$#codes is perfectly legal in Perl to return the number of elements in an array. Much simpler than using $numcodes = @codes, which requires an additional variable to be defined/used. I use the same method in the same script externally... While attempting to track down the reason for the problem, I put the same subroutine into it's own script file and ran it from a command prompt. The script works perfectly fine with no errors. MUclient just does not like the rand() function.




Any thoughts on the Net::Ping with Time::HiRes problem?




Addendum:
I don't think for ($n=0; $n<@codes; $n++) would work, since you can't use an array variable in that way. It would have to be changed to a scalar via either scalar(@codes) or my($numcodes)=@codes

Additional Addendum:
Yes, I did try using scalar(@codes). As I stated above, MUclient does not like the rand() function.

Additional Additional Addendum:
I tried using Immediate in MUclient... I tried $world->note(rand(10)) and received the following error dialog:

Error number: -2147467259
Event:        Execution of line 1 column 0
Description:  Internal Error
Line in error: 

Called by:    Immediate execution
Amended on Sun 02 Mar 2003 07:52 AM by 1of10
Australia Forum Administrator #6
I can get:

/$world->note(rand(10))

to work just typing it into the command window.

I suspect you have an old version of Perlscript. Try looking at the version of PerlSE.dll wherever that is, mine is 5.6.1.633.

Make sure you have not only downloaded it but activated it. I suspect the other problems may be related to this one.
Australia Forum Administrator #7
You could try this to check the version:


$world->note ($]);


I got: 5.006001
Amended on Tue 04 Mar 2003 04:31 AM by Nick Gammon
Canada #8
You have a fairly old version of Perl. Mine is 5.8.0.804. $] returned 5.008. I have used both run~$world->note(rand(10)), where run~ is my script prefix, and Game / Immediate (Ctrl+I). Both ways of immediate execution return the same error dialog noted in my previous post.

Let me guess, next suggestion is that I downgrade my Perl? I'd really prefer not to do that. I much prefer to have the latest and greatest versions.

Addendum:
FYI, I checked my Perl version from the command prompt with Perl -V (which returned (revision 5 version 8 subversion 0) near the top and ActivePerl Build 804 near the bottom of the configuration spam it outputs). I used $] in the command prompt and in MUclient. I searched for all occurances of PerlSE.dll on my hard drive and found only the one in C:\Perl\bin, which said 5.8.0.804.
Amended on Tue 04 Mar 2003 05:06 AM by 1of10
Australia Forum Administrator #9
There is a known bug in that version of Perl. See rand () terminates script when using isapi.

Note that the bug report mentions your exact version (5.8.0 build 804) and that the report says that the bug does not appear when running from the command line - the exact symptoms you report.

So yes, try downgrading. :)

Australia Forum Administrator #10
As I said earlier, MUSHclient simply calls the script engine and passes down the whole script. It isn't really possible for it to "not like" particular keywords in your script. The problem would have to be in the script itself, or in the script engine.
Canada #11
It must have been a bug in 803 as well, as I upgraded to 804 in the hopes that it would fix the problem. I did this before posting my original message.

Appologies for wasting time with this. Since it worked in the command prompt, I never thought ActivePerl could have been at fault.

I shouldn't say never... It was my first thought, which prompted the upgrade to 804. But upon seeing the same failure in 804, I tested in an external script in the command prompt. When that worked, I assumed MUclient. :p



Any thoughts on the Net::Ping with Time::HiRes problem, mentioned in the original post?
Amended on Tue 04 Mar 2003 06:19 AM by 1of10
Australia Forum Administrator #12
You have installed PerlScript which is an external package to MUSHclient, and then Net::Ping and Time::HiRes and they don't all work perfectly together? This is really falling outside the scope of supporting MUSHclient.

Try going to this web page:

http://bugs.activestate.com/ActivePerl/

Enter "net::ping" as a search term and you will see a heap of entries for problems with it. I can't help you much more than to suggest you try to follow up some of them, or stop using the HiRes package.
Canada #13
I'll poke around ActiveState and try some tests. If/when I come up with something, I'll post to ActiveState (if I can).

Thanks for all your help. :)
Canada #14
Just a comment on really f***ed up things...

I guess I'll have to wait for 5.8.0.806 or whatever version fixes the rand() bug, 'cause 5.6.1.635 is too old! I've experienced several problems attempting to install and use Perl packages with 635. I have no choice but to use 805.

Oh, and Net::Ping with Time::HiRes works flawlessly in an external script from command line. I guess that's another bug in the 80x versions... :(

Addendum:
The good news, however, is that Time::HiRes is working with 805. *boggle*