|
zrjones Newbie
Joined: 19 Dec 2007 Posts: 5
|
Posted: 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} |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: 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 |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: 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. |
|
|
|
|
|