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


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Tue Mar 01, 2011 5:12 am   

[3.33a] #DELKEY failing with dots in key
 
Code:

<class name="Test Dot" id="130">
  <var name="testDB" type="Record" id="129">
    <value>1.test=Is something|test.test=Something else|test=Third thing</value>
    <json>{"test.test":"Something else","1.test":"Is something","test":"Third thing"}</json>
  </var>
  <alias name="dotest" id="131">
    <value>#IF (%null( %params)) {
  #PRINT %if( %iskey( testDB, "1.test"), %concat( "Exists: ", %db( testDB, "1.test")), %concat( "Doesn't Exist: ", %db( testDB, "1.test")))
  #PRINT %if( %iskey( testDB, "test.test"), %concat( "Exists: ", %db( testDB, "test.test")), %concat( "Doesn't Exist: ", %db( testDB, "test.test")))
  #PRINT %if( %iskey( testDB, "test"), %concat( "Exists: ", %db( testDB, "test")), %concat( "Doesn't Exist: ", %db( testDB, "test")))
  } {
  // Try %params
  #PRINT %if( %iskey( testDB, %params), %concat( "Exists: ", %db( testDB, %params)), %concat( "Doesn't Exist: ", %db( testDB, %params)))
  #DELKEY testDB %params
  #PRINT %if( %iskey( testDB, %params), %concat( "Exists: ", %db( testDB, %params)), %concat( "Doesn't Exist: ", %db( testDB, %params)))
  }</value>
  </alias>
</class>


type the following in the command line:
dotest
dotest 1.test
dotest test


You will notice that 1.test refuses to be removed, while test is removed just fine. Same happens with test.test not being removed.

Edit: Happens with %delkey() too
Edit 2: Trying to %concat() keys together also doesn't work
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue Mar 01, 2011 1:19 pm   
 
Dots should not be used as part of key names. Dots are used as part of the shorthand dot notation, so using dots within key names will break things.
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Tue Mar 01, 2011 3:01 pm   
 
I figured that would be part of the problem, but hoped there was some way to fix it. There's really no way to avoid dots in the key names as dots are how my MUD distinguishes multiple things of the same name from one another. But if I know this won't be changed or fixed, I can begin work on a little mini parser to store multiples in a different format and convert them to dots later. It's just a lot of work, so I don't want to do it if this will be fixed.

Keep in mind that the dots work perfectly fine in almost everything else as far as keys go, including the most important bit, accessing info from the record. The only thing I haven't seen the dots work in is #DELKEY
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Tue Mar 01, 2011 4:35 pm   
 
Will keys have any conflict with * in them? Thinking of using that as my parse character for the dot replacement, if I need to.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue Mar 01, 2011 5:34 pm   
 
I don't see how it _can_ be "fixed". In your example, what do you think would happen if you did #SHOW @testDB.1.test, or #SHOW @testDB.test.test?
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue Mar 01, 2011 5:38 pm   
 
I don't know offhand whether "*" would be a problem in key names. I suspect it would be fine, but I would suggest something more innocuous and less likely to cause parsing problems when using the values in scripts, like "_" or "#".
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Tue Mar 01, 2011 5:43 pm   
 
Rahab wrote:
I don't see how it _can_ be "fixed". In your example, what do you think would happen if you did #SHOW @testDB.1.test, or #SHOW @testDB.test.test?


I understand that the dot syntax could cause conflicts with certain functions. However, since it doesn't cause conflicts with many of the functions and commands already (i.e. #ADDKEY, %iskey) etc... it's clear that there is some sort of solution being used. Perhaps this is merely an unintended consequence as a result of some other things CMUD is doing, it wouldn't be the first time. In that case, it's obvious that it wouldn't ever be "fixed". Zugg could also just want it to work this way, in which case, once again, it wouldn't be able to be "fixed". However, the fact that a variable containing the dot syntax seems to work in some cases is what led me to wonder why it doesn't in others.

For the record though, I would expect #SHOW @testDB.1.test to look for the key named 1 and then to further look for the sub key, as part of the DB record of 1 of test and display its value. However, if I did #SHOW %db( testDB, "1.test") I would expect it to show the value for the key named 1.test
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue Mar 01, 2011 6:04 pm   
 
How would you do a #SHOW of your "1.test" key using the dot syntax? The dot syntax needs to work for every valid key name. If someone were using the dot syntax (many use it in preference to %db() ) and it didn't work on a valid key name, the user would rightfully consider that a bug.
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Tue Mar 01, 2011 7:04 pm   
 
The best way would probably be expansion, something like #SHOW @testDB.{"1.test"}

The info between the brackets would tell CMUD that it should be taken as a literal key name instead of being parsed with the dot. Thus:
testDB = {
1.test = "This is a value",
1 = {test = "This is a sub value of a value", something = "This is yet another sub value"}
}
#SHOW @testDB.{"1.test"}
would show "This is a value"

but
#SHOW @testDB.1.test
would show "This is a sub value of a value"
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Wed Mar 02, 2011 6:49 pm   
 
Have you considered changing the periods to another character that doesn't have a special purpose and won't otherwise appear in the strings with %replace() before saving that string as part of a key/value pair, then changing it back again the same way?

ie %replace("1.test", ".", "_") when you define the record variable, then %replace("1_test", "_", ".") when you access or manipulate it later.
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Mar 02, 2011 8:47 pm   
 
DraxDrax wrote:
Have you considered changing the periods to another character that doesn't have a special purpose and won't otherwise appear in the strings with %replace() before saving that string as part of a key/value pair, then changing it back again the same way?

ie %replace("1.test", ".", "_") when you define the record variable, then %replace("1_test", "_", ".") when you access or manipulate it later.


Yeah (it was already discussed in the thread). In lieu of the fact that it might not be adjusted I'd already had something set up in mind to parse it (I went with "#" though). I just figured, if it was something odd about how #DELKEY works (since other commands and functions handle it just fine) then maybe it would be fixed and I wouldn't have to do some hokey parsing to get it done. But I did and so it's done. I got it working two nights ago Wink
_________________
Listen to my Guitar - If you like it, listen to more
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