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
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Thu Aug 09, 2007 2:54 pm   

[1.34] Something odd going on with my data record here
 
I noticed that my deep wounds curing (Lusternia) was behaving differently from how I coded it, and when I began to look into the problem, I found inconsistencies in the way CMUD was handling my variables. Basically, I have a "wounds" data record variable that tracks rough numeric damage values on various body parts. I'm looping through the keys to find the body part with the most damage, so I can heal it. I managed to strip it down a bit until it is something I can reproduce in a blank session reliably.

Code:
#ALIAS i_woundhealing {
$wounding = 0
$wound_heal = ""
#LOOPDB @wounds {
  #IF (%val > $wounding) {
    $wound_heal = %key
    $wounding = %val
  }
}
#IF ($wounding > 0) {
  #SWITCH (%pos("leg", $wound_heal)) {
    $wound_heal = "legs"
  } (%pos("arm", $wound_heal)) {
    $wound_heal = "arms"
  }
  i_deepheal $wound_heal
}
}
#ALIAS i_deepheal($body_part) {
#IF ($body_part) {
  apply health to $body_part
}
}

#ADDKEY wounds chest 1600
#ADDKEY wounds gut 2400
#ADDKEY wounds head 800


With the sample data pre-populated here, what should happen is that "apply health to gut" is executed. What happens, though, is that "apply health to head" comes out. It seems to me that the %key is being treated as a reference rather than a static value, thus the value of $wound_heal changes when %key changes, but that could just be appearances.

The other odd thing is that if I edit the script a bit in the editor, the alias spits out the correct command. So, it seems that my code is working as it is after a bit of tinkering (changing none of the logic, I promise), but this is still something I consider a bug.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Thu Aug 09, 2007 3:41 pm   
 
Confirmed. And you're right, the variable assignment must be storing the references to %key and %val instead of the real value. Simply using %eval as below causes it to work properly.

Code:
    $wound_heal = %eval(%key)
    $wounding = %eval(%val)
_________________
Asati di tempari!
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Thu Aug 09, 2007 8:52 pm   
 
Yup. That's the workaround I ended up trying and found it worked properly then.
Reply with quote
Zugg
MASTER


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

PostPosted: Fri Aug 10, 2007 1:53 am   
 
I'm no longer in front of my work computer with CMUD at the moment, but can someone test this and see if %key and %val are defined just inside the #LOOPDB before the #IF statement? In other words, I need to know if it's the #IF block that is causing the problem. So something like this:
Code:
#LOOPDB @wounds {
  #SHOW "Key : " %key "Val : " %val
  #IF (%val > $wounding) {
    $wound_heal = %key
    $wounding = %val
  }

would help me determine where %key and %val are getting messed up.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Fri Aug 10, 2007 2:14 am   
 
I ran that code and got
Code:
Key :  chest Val :  1600
Key :  gut Val :  2400
Key :  head Val :  800


as expected.
_________________
Asati di tempari!
Reply with quote
forren
Novice


Joined: 26 Apr 2007
Posts: 44

PostPosted: Mon Aug 13, 2007 5:27 pm   
 
Larkin - the same exact thing happened to me when working on my wound curing. I patched it up by using local variables $key and $val as %key and %val. I'll post my script a bit later - was going to submit it anyway, but I've been pretty busy.
Reply with quote
Zugg
MASTER


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

PostPosted: Wed Aug 15, 2007 7:43 pm   
 
Yep, CMUD was storing a direct reference to %key and %val instead of a copy of the value. It's fixed in v2.0 now. Another good obscure bug, so thanks for reporting it.
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