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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Wed Oct 01, 2008 8:53 pm   

#Additem bug?
 
OK, I'm pretty sure this will end up being my own shortcomings of some sort, but I figured I'll write it anyway.

Did a test class which I'll paste here for others to try. Will try to explain above.

Code:

<class name="Test" id="193">
  <alias name="case" autoappend="true" id="123">
    <value>#if (%numitems(%db(@TestDB,HealsNeeded)>1)) {#forall %db(@TestDB,HealsNeeded) {#if (%iskey(@TestDB,%i)>=1) {#additem TestQ %additem(%db(@TestDB,%i),@TestQ)}}}
</value>
  </alias>
  <var name="TestDB" type="Record" id="191">first="take something|heal"|second="take something else|heal"|HealsNeeded="first|second"</var>
  <var name="TestQ" type="StringList" id="192">"""take something|heal"""|"""""""take something|heal""""""|""take something else|heal"""|"""""""take something|heal""""""|""""""""""""""take something|heal""""""""""""|""""take something else|heal""""""|""take something|heal"""|"""""""take something|heal""""""|""""""""""""""take something|heal""""""""""""|""""take something else|heal""""""|""""""""""""""take something|heal""""""""""""|""""""""""""""""""""""""""""take something|heal""""""""""""""""""""""""|""""""""take something else|heal""""""""""""|""""take something|heal""""""|""take something else|heal"""</var>
</class>


As the code above shows, using %additem within #additem to restrict same things being added over time produces weird input being added as items for the TestQ String List Variable. It doesn't mean if you use Case Alias once or more (in code above, I used it twice in a row, but just now used just once and input is basically the same).
Now, I've been using the same %additem idea when adding new values for a DB Variable key and it has always worked, so I intuitively thought that it might be the case here, too - I realize that I may be wrong, though.
Anyway, when I use the default %additem aspect: TestQ=%additem(%db(@TestDB,%i),@TestQ), everything is added without any non-needed quotes or spam.

Thoughts?
_________________
The Proud new owner of CMud.

--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
--------------------------------
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Wed Oct 01, 2008 9:07 pm   
 
Maybe I lost something in translation, but if you're not wanting same items to be added as per your first sentence below the code, #ADDITEM already does that. It does not add duplicates. %additem does, though. Just a thought.

Charneus
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5187

PostPosted: Thu Oct 02, 2008 1:34 am   
 
I think #ADDITEM is doing what is it supposed to with your code. You do understand that when you use either %additem or #ADDITEM with a value that is alread a string list it will add quotes in order to keep those items together. A simple example:
#ADDITEM a {b}
#ADDITEM a {c|d}
#ADDITEM a {e}
#SHOW %item(@a,2)

Usiing the combination of %additem and #ADDITEM as you are you are first adding a small list to the existing list as a single item, then adding the entire existing list to itself again as a singe item. This is what is leading to your huge mess of quotes.

About all I can suggest is tell us the real details of what you want to do with the data, and we may come up with some better choices for how to store it.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
ralgith
Sorcerer


Joined: 13 Jan 2006
Posts: 715

PostPosted: Thu Oct 02, 2008 7:14 am   
 
Yes, Vij already nailed it. #ADDITEM does not allow dupes. However you're adding a %additem (which can allow duplicates) into a #ADDITEM but in such a way that it is making it unique because it adds all that extra quoting, so it adds it to the list. I think you may have been a little confused as to the purpose of the 2 commands here :)
_________________
CrossOver: Windows Compatibility on Mac and Linux CMUD Advocate
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Thu Oct 02, 2008 8:09 am   
 
Heh, sorry to cause all that trouble. To be honest, I really wasn't confused. As I wrote in OP, I intuitively started to use the same scheme as
I have always done for #addkey in case I had to add new values into a certain key. I suppose one can never completely understand
how the little grey cells work, can they?

Anyway, obviously Var=%additem(..) scheme is the way to go. I'll try not to post dumb things with "bug" in title not having them deeply
analyzed and pondered upon beforehand.

Thanks all who took time to reply.
_________________
The Proud new owner of CMud.

--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
--------------------------------
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion 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