Crashing Mushclient with a script

Posted by AndrewWalmsley on Sat 25 May 2002 03:58 PM — 7 posts, 23,455 views.

#0
Trying to write a nice simple script to colour my hp on prompt line depending how many left as %.
However, replacing $world-Note with $world->Tell in follwing example crashes the client. I need to use tell to avoid colouring the rest of the line. (going to do the same to mana and move).

Anmyone spot what I've done wrong here?

I've taken out the rest as that seems to work.
prompt is
prompt : area name : hp : maxhp : mana : mv :
trigger works off ^prompt : *


sub ColourHP
{
	@promptline=split(/:/,@_[1]);
	$currentHP = @promptline[1];
	$maxHP = @promptline[2];
	$percentHP = $currentHP / $maxHP * 100;

	foreach $pr (@promptline) {
		$world->Note("$pr");
	}
}
#1
oopps forgot, version is 3.20
Australia Forum Administrator #2
I cannot reproduce that, either in the latest version or 3.20. Can you give the exact line you are matching on?

For example, if I get the line:


prompt : area name : 15 : 100 : 200 : 300 :


I see the following tells:


prompt area name 15 100 200 300


It seems to have done its stuff. The colons are gone, and there is no crash.
#3
Just rechecked to see if reboot fixed problem, and it didn't.

The exact line I'm matching on is

prompt : Valley of the Elves : 4951 : 4951 : 1429 : 802 


world Note give the output I'd expect i.e.

prompt 
 Valley of the Elves 
 4951 
 4951 
 1429 
 802 


rest of code (all commented out is)

#	if ($percentHP >= 100)
#	{
#		$world->NoteColourname ("lawngreen","");
#	} 
#	elsif ($percentHP >= 50)
#	{
#		$world->NoteColourname ("green","");
#	}
#	elsif ($percentHP >= 25)
#	{
#		$world->NoteColourname ("crimson","");
#	}
#	else
#	{
#		$world->NoteColourname ("red","");	
#	}
#	$world->Tell("@promptline[2]");
#	$world->notecolourfore=$oldforecolour;
#	$world->Note("hp @promptline[4] mn @promptline[5] mv"); 
#4
OK, now I'm totally confused. Upreved to 3.22, script still crashed client, rewrote it to below, and this works, even if uncommenting foreach debugging bit.
<shrug>



sub ColourHP
{
	@promptline=split(/:/,@_[1]);
	$currentHP = @promptline[2];
	$maxHP = @promptline[3];
	$percentHP = $currentHP / $maxHP * 100;

#	foreach $pr (@promptline) {
#		$world->Tell("$pr");
#	}
	$world->Tell("@promptline[1]");
	if ($percentHP >= 100)
	{
		$world->NoteColourRGB(0xCCCCCC,0x00);
		
	} 
	elsif ($percentHP >= 50)
	{
		$world->NoteColourRGB(0xCC00,0x00);
	}
	elsif ($percentHP >= 25)
	{
		$world->NoteColourRGB(0xAA,0xFF);
	}
	else
	{
		$world->NoteColourRGB(0xFF,0x00);	
	}
	$world->Tell("@promptline[2]");
	$world->NoteColourRGB(0xCCCCCC,0x00);
	$world->Tell("hp @promptline[4] mn @promptline[5] mv\n");                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
}
Australia Forum Administrator #5
Could be your version of PerlScript is faulty. :)

My version of PerlSE.dll is 5,6,0,613 (ActivePerl 5.6.0.613).

Even if yours is later that doesn't prove much - later releases can be more unreliable than earlier ones. I would try downloading a new version of Perlscript.
Australia Forum Administrator #6
You say that "note" works but "tell" doesn't. Internally note and tell are almost identical. Here is the actual code for the world.note from my C++ code ...


const char ENDLINE [] = "\r\n";   // line terminator

void CMUSHclientDoc::Note(LPCTSTR Message) 
{
  CString strMsg = Message;

  if (strMsg.Right (2) != ENDLINE)
    strMsg += ENDLINE;      // add a new line if necessary

  Tell (strMsg);
}


You can see that note only does one extra step - adds a newline if it isn't already there, then calls Tell. Unless the newline somehow prevents a crash - something that is a bit far-fetched, the problem is not in MUSHclient. In any case, you could test that by using "tell" but adding \r\n to the text, so the Note and Tell do exactly the same thing.