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 ➜ General ➜ Need help with jscript for checking my health...

Need help with jscript for checking my health...

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


Posted by Phatj   (4 posts)  Bio
Date Mon 24 Feb 2003 01:20 AM (UTC)
Message
Im having a problem with the below script. Everytime I call it with an alias, it returns the same amount of health and mana, even after a battle when my health has changed. Can anyone help me with this problem on updating my stats? Thanks.


////////////////////////////////////////////////////
var line, total_lines;

total_lines = world.GetLinesInBufferCount ();


//Determines health!
function GetHealthandMana(){

stats = world.GetLineInfo (total_lines, 1);
actualHealth = stats.slice(0,3);
tempstring = stats.slice(6,13);
actualMana = tempstring.slice(0,3);

}


//puts everything together
function Main(){

//start by checking health and mana
GetHealthandMana();
world.note (actualHealth + " " + actualMana);
if(actualHealth != 888){
world.send (sleep);
world.DoAfter +24 (wake);
world.DoAfter +6 (stand);
}else{
world.send ("laugh");
}
}

Top

Posted by Phatj   (4 posts)  Bio
Date Reply #1 on Mon 24 Feb 2003 01:22 AM (UTC)
Message
BTW- here is some output from the mud

///////////////////////////////

Meihua arrives from the north.
888h, 642m ex-
Meihua leaves to the southeast.
888h, 642m ex-
With a flick of its small whiskers, a young rat dashes out of view.
888h, 642m ex-
Zech, Dedicated of Light asks, in Xorani "What is so funny?"
888h, 642m ex-

//////////////////////////////

every newline begins with the health/mana
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #2 on Mon 24 Feb 2003 04:38 AM (UTC)
Message
This is a very roundabout way of doing it. I would use a trigger, and simply set up two wildcards. eg


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="*h, *m ex-"
   name="process_health"
   script="DoHealth"
   sequence="100"
  >
  </trigger>
</triggers>


Then wildcard 1 is your health and wildcard 2 is your mana. Then extract them in a simple trigger script. There are dozens of examples on the forum here.

- Nick Gammon

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

Posted by Ked   Russia  (524 posts)  Bio
Date Reply #3 on Mon 24 Feb 2003 08:52 AM (UTC)
Message
Although, Nick's suggestion wouldn't really work I'd still go with it, Phatj. In fact I already did. :P

Reason it won't work is that the '*h, *m ex-' trigger wouldn't match, since 1) that form of prompt appears with no newline; 2) the 'ex' portion changes all the time, so you need to account for that also. But that's just details, the approach itself is perfectly valid.

The only situation where you'd want to know how much health/mana you have is during combat (or bashing) and in both of those, things happen so fast that a prompt without a newline rarely ever hangs on the screen for even a second, so you can safely use a trigger to pull the stats directly from wildcards. Here's a regexp trigger that I use to account for the 'ex' portion and pull out 2 wilcards with stats:


<triggers>
  <trigger
   enabled="y"
   regexp="y"
   match="^(\d+)h\, (\d+)m (\D{0,6})-.*$"
   name="process_health"
   script="DoHealth"
   sequence="100"
  >
  </trigger>
</triggers>


That'll return 3 wildcards, but you only need the first 2 really. Accounting for the 'ex' (cexkdb - in full) is safer done with using a character class - something that'll match on any combination of characters 'cexkdb' but no more than 6 of them and in that order (ceb|exk|ed...) - but I am too lazy to figure it out, so I just use the much broader (\D{0,6}).

Top

Posted by Ked   Russia  (524 posts)  Bio
Date Reply #4 on Mon 24 Feb 2003 09:00 AM (UTC)
Message
Silly me - that trigger would screw up your entire list of them in worst case scenario or just wont match in the best one. Here's the one you really need:

 
<triggers>
  <trigger
   enabled="y"
   regexp="y"
   keep_evaluating="y"
   match="^(\d+)h\, (\d+)m (\D{0,6})-.*$"
   name="process_health"
   script="DoHealth"
   sequence="1"
  >
  </trigger>
</triggers  


As you can see, it is the first trigger to be matched on any line you recieve from the MUD, but if it matches then all other triggers aren't ignored and attempts to match them continue on the same string (because of the Keep evaluating option being selected)
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.


12,322 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.