Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
Urit
Novice


Joined: 23 Jun 2005
Posts: 32

PostPosted: Sat Oct 02, 2010 11:51 pm   

[3.30 pro] Async(?) GMCP processing causing variable population problems
 
Bug:

GMCP processing seems to be async, so variables calling %gmcp without eval returns 1 rather than the value.

Reproduction:

Take the following code:

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <trigger name="TelnetPrompt" type="GMCP" param="201" priority="1" trigontrig="false" regex="true" copy="yes">
    <pattern>Char.Vitals</pattern>
    <value>OldHealth = @CurHealth
CurHealth = %gmcp.char.vitals.hp
VitalChange.Health = (@CurHealth - @OldHealth)
MaxHealth = %gmcp.char.vitals.maxhp
OldMana = @CurMana
CurMana = %gmcp.char.vitals.mp
VitalChange.Mana = (@CurMana - @OldMana)
MaxMana = %gmcp.char.vitals.maxmp</value>
  </trigger>
</cmud>


It's a fairly normal GMCP trigger, right? Well, connect to Achaea (achaea.com 23) and log in with a character. Paste that code into a blank session, thus creating a new trigger.

You'll get the following variables created:

CurHealth
CurMana
OldHealth
OldMana
VitalChange

Do "LOOK" or some other command. Now do #echo @VitalChange
Code:
Health=-3219|Mana=-3219


WHAT?

Run the check manually: #echo Health Change: (@CurHealth - @OldHealth) Mana Change: (@CurMana - @OldMana)
Code:
Health Change: 0 Mana Change: 0


DOUBLE WHAT?

Now, there's a TRIPLE WHAT workaround:

Change TelnetPrompt to the following code:

Code:
OldHealth = @CurHealth
CurHealth = %eval(%gmcp.char.vitals.hp)
VitalChange.Health = (@CurHealth - @OldHealth)
OldMana = @CurMana
CurMana = %eval(%gmcp.char.vitals.mp)
VitalChange.Mana = (@CurMana - @OldMana)


LOOK. Wait for prompt. #echo @VitalChange
Code:
Health=0|Mana=0


TRIPLE WHAT?

Weren't we not supposed to use %eval anymore?

Hypothesis:
%gmcp.char.vitals.hp evaluates to "1" (hence the -3219) value in the first test during compilation, but if you defer compilation via %eval it returns the actual value from that pseudofunction.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Sun Oct 03, 2010 7:33 pm   
 
No, you shouldn't be using %eval.

How is your @CurHealth variable being initialized in your session? You realize that it will normally save this variable across sessions so unless you are setting it in some other script, that might be causing the problem. You need some way of determining the first time your trigger fires so that it can initialize these variables properly.

I have no idea why %eval is making any difference, but it is definitely not something I recommend using in the GMCP trigger since %eval causes the entire compiler and parser to be executed which is slow, so it can lag your session.
Reply with quote
Urit
Novice


Joined: 23 Jun 2005
Posts: 32

PostPosted: Thu Oct 07, 2010 3:15 am   
 
1. I actually had the variables set before I created the script. I didn't include the definitions in the code because the trigger would create them on its own.
2. I had no other sessions/windows open. I closed cmud, opened it, escape, file, connect, achaea.com 23, login, open settings, paste. Look around a bit, walk around a few rooms, come back, check variables.
3. This is NOT something that happens the first time the triggers fire. I can see uninitialized vars being a problem, but these are filled EVERY PROMPT.

Below is the definition for my vars:
Code:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <var name="CurHealth" copy="yes">
    <value>3020</value>
    <json>3020</json>
  </var>
  <var name="CurMana" copy="yes">
    <value>3220</value>
    <json>3220</json>
  </var>
  <var name="OldHealth" copy="yes">
    <value>3020</value>
    <json>3020</json>
  </var>
  <var name="OldMana" copy="yes">
    <value>3220</value>
    <json>3220</json>
  </var>
  <var name="MaxMana" copy="yes">
    <value>3220</value>
    <json>3220</json>
  </var>
  <var name="MaxHealth" copy="yes">
    <value>3220</value>
    <json>3220</json>
  </var>
</cmud>
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net