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
njkc07
Beginner


Joined: 09 May 2008
Posts: 15

PostPosted: Wed May 14, 2008 10:07 pm   

avoiding duplicates in databases
 
I realize this may be posted in the wrong section. If it is please forgive me.

I was recently perusing the help files for CMUD's database and saw a help on making a database for identifying objects. Thought it would be great and it works great! the only problem I have is that it doesn't state a way to avoid making duplicate records of the same object. I tried putting the object's name from identify in a strig list and the checking the string list for that name but it isn't working.

Code:
Object '(*)', Item type: (%w)

Trigger capture

Code:
#IF (%ismember(%1, idItems)) {#T- identify;#EC Already know about that item} {#ADDITEM idItems %1}

Adding objects name to stringlist idItems

Obviously the identify class is where all my triggers are to populate a database record and add a new record to my db.

It's not working. plenty of records of the same object, never once has it closed the class and ecoed anything.

I am sure there has to be an easier way to avoid getting duplicates in the db and would be glad to hear. If not then would be glad to hear what I am doing wrong here. I know if this were SQL or Access I could just declare objName a primary key and that would solve it but don't see any way to establish a primary key in CMUD
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Wed May 14, 2008 10:12 pm   
 
%additem allows dups, #additem doesn't.

idItems=%additem(%1,@idItems)



Prog
_________________
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
njkc07
Beginner


Joined: 09 May 2008
Posts: 15

PostPosted: Wed May 14, 2008 10:31 pm   
 
I don't want duplicates. for instance right now I keep identifying the same item. The object name is "a pair of red steel greaves" (no quotes obviously). It doesn't seem to be checking if that name is in my idItems string list. The name is in there, I see it in there. So it should be turning off the identify class and telling me I already have id'ed that item or whatever I told it to echo.


*EDIT:

Never mind I am an idiot at times and forgot the @ infront of my string list when checking. Thanks for trying to help!!
Reply with quote
njkc07
Beginner


Joined: 09 May 2008
Posts: 15

PostPosted: Wed May 14, 2008 10:39 pm   
 
one last question. I get this at some items in the bottom of the identify.

Code:
Can affect you as :
   Affects: DEX By 2
   Affects: MAXMOVE By 10


I have a field in my db for this and it is type memo (probably not the best type for it but thought it would be easier). How can I capture all the affects message and put them into the single memo field in my db?

I realize I can make a trig to capture each individual Affects: line but awfully time consuming, not mention I would have to make an individual field for each affect possible, which would be quite a few.
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Thu May 15, 2008 12:46 am   
 
You may store it into the database as a stringlist or, alternatively, you can convert the stringlist to a string (using " " as the separator) and store it, instead. If your data contains blanks, you can use some other (unused) character as your separator.
_________________
Sic itur ad astra.
Reply with quote
njkc07
Beginner


Joined: 09 May 2008
Posts: 15

PostPosted: Thu May 15, 2008 2:06 am   
 
Anaristos wrote:
You may store it into the database as a stringlist or, alternatively, you can convert the stringlist to a string (using " " as the separator) and store it, instead. If your data contains blanks, you can use some other (unused) character as your separator.


These sound like great things but unfortunately my knowledge of such is quite limited. Perhaps you could give some examples on how they are syntax wise? Thanks for the help!!
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Thu May 15, 2008 2:41 am   
 
A stringlist can be created by using the #ADDITEM command or the %additem() function. By using the command you make sure that no duplicate data is added to the stringlist. if you want duplicate items, or don't care if you have any, you can use the function.
A stringlist is a string with the following format:
Code:

value1|value2|value3|.....|valuen

The | separator is a must for a stringlist.
You use the %numitems() function to find out how many elements exist in the stringlist. You use the %item() function to extract values from the list by providing a 1-based index.
Note that a stringlist which has its separator (|) replaced by a " ", becomes a standard string. Assuming that the items don't have any blank characters in them. The reverse is also true.
The corollary from this is that you can use the %replace() function to convert strings to stringlists and vice versa. Also, the %expandlist can be use for conversion.
From this you can gather that this is something you can do:
Code:

#ADDKEY dbvar data=%replace(stringlistvariable,"|"," ")

This will add the data key to the dbvar variable, for instance. You can use any replacement character you like, so if your items have blanks in them, you can choose another replacement for your stringlist separator.

These are just examples of what you can do. You must choose a suitable method for your specific application. Your application may not be suitable for any of these ideas.

I suggest you read this page to become familiarized with the concept of stringlists.
_________________
Sic itur ad astra.
Reply with quote
njkc07
Beginner


Joined: 09 May 2008
Posts: 15

PostPosted: Thu May 15, 2008 3:10 am   
 
I get string lists just didn't know I could use replace to make it into a solid string. Is " " mandatory or could I replace with ", "? Thanks for the help. you all here are awesome
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4690
Location: Pensacola, FL, USA

PostPosted: Thu May 15, 2008 4:02 am   
 
you can replace it with whatever you wish
_________________
Discord: Shalimarwildcat
Reply with quote
OxnyxWS
Newbie


Joined: 23 Oct 2006
Posts: 8

PostPosted: Tue May 27, 2008 3:12 am   Different Solution
 
I tried the #ADDKEY thing but as far as I could tell the problem was that of course you want to clear the VAR of the setting after adding the data to the database so #ADDKEY just didn't cut it.
#QUERY on the other hand, is helpful cause it checks the database. Below is the code I currently using. @Item is a VAR that has the new entry for the database I query the name field (echo if currently in database) then do a null name check and add the data. Hopefully this helps Cool
Code:

#IF (%QUERY((&Name = @Item.Name)))
{#Echo @Item.Name is found in database; #DBRESET}
{#Echo @Item.Name is a new item; #DBRESET
    #IF (!%null(@Item.Name)) 
      {#Echo Data is present; #NEW All|Database @Item 
      #EC Added @Item.Name}
      {#ECHO Null Name }
}

#T- Gather
#T- AddData
#VAR Item " "
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