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
zrjones
Newbie


Joined: 19 Dec 2007
Posts: 5

PostPosted: Wed Mar 16, 2011 7:50 am   

DATABASE MODULE Version 2.xx
 
Monster Database Update

I'm trying to create a Monster Database with stats on each monster. I'm having serious problems with syntax and updating records in the database with new data. Before storing data, I would like to search the database to make sure the monster doesn't already exist. If he exist, I would like to check certain values to see if the database should be updated, and if the monster doesn't exist, I'd like to create a new record. I've done a lot of reading, but I'm not sure if what I have so far is the best method. I need something that will work with the built-in database module on version 2.xx. My biggest problem is retrieving the record number of the record that needs updating and updating that record. Can someone make this method work?


recordexists=0
#DBLOAD mo
#DBFIRST
#WHILE (!%null(%rec)) {
#IF (&Name=@mon) {
#ECHO RECORD FOUND
recordexists=1
temphp=&HP
#ECHO @dmg " " @temphp
#IF (@dmg<@temphp) { <- Is there a problem with NESTED #IFs
#ECHO Needs update
//#DBPUT %rec {HP=@dmg} <- This line doesn't update the HP field correctly
}

}
#DBNEXT}
#IF (recordexists=0) {#ECHO STORE NEW RECORD HERE}
Reply with quote
shalimar
GURU


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

PostPosted: Wed Mar 16, 2011 10:27 am   
 
with the new json standard, it might be easier to make a database variable

$damage=567
$name=some monster name
$test=@{monsters.$name.HP}
#IF ($test<$damage) {monsters.$name.HP=$damage}

If a given value doesn't yet exist it returns %null, so there is no need to test for preexisting records
_________________
Discord: Shalimarwildcat
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed Mar 16, 2011 7:11 pm   
 
He is not upgrading to 3.xx, so he can't use the new json stuff.

I think you want the %query() function, zrjones. That does the search and matching for you.
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