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
groundzero2010
Novice


Joined: 30 Sep 2004
Posts: 47
Location: Arkansas

PostPosted: Wed Mar 28, 2018 10:27 pm   

Abort New DB Record on duplicate
 
I'm having a little issue where my code isn't working the way I think it should. Similar to an item identify database, I've created a mob database.
When I cast identify on a mob it searches and checks if it already exists in the database. This is working correctly however when the Yes/No pops up asking if I want to abort the save or keep, the abort doesn't abort the save. It still adds the duplicate mob. The below code is all in an alias which is called by a trigger. I have a record variable called mobStats that is holding the identify values then cast it to the database mobStats.
Here is my troubled code:
Code:

#PROMPT mobStats.aggro "Is the mob aggro? Yes/No"
#PROMPT mobStats.notes "Load items or notes?"

#IF !%null( %find( @mobStats.Name, All, Name)) {#dbget %find( @mobStats.Name, All, Name)
#sa %rec
#YESNO "A duplicate mob already exists, abort?" {Yes, Abort:#abort 1} {Keep:#say Adding}}


#DBLOAD mobStats
#SA Saving to database

#NEW All @mobStats
#dbsave
#dbreset

#SA Clearing cache
resetMobStats

#t- RetrieveMob

Reply with quote
groundzero2010
Novice


Joined: 30 Sep 2004
Posts: 47
Location: Arkansas

PostPosted: Thu Mar 29, 2018 2:39 pm   
 
Moved the loaddb to the top of the script so it would make sure the database was open to check for duplicates. Added the #closedb at the bottom so I don't run into issues with saving items to a seperate database. The duplicate prompt 'abort 1' option still didn't seem to work, however, I put the #closedb command inside the abort prompt option and this seems to work. Not sure if this is the correct way to do things, but it closes the db so it can't write to it. The rest of the script, dbsave, dbreset, resetMobStats, etc. still all run which isn't how I expect it to run since abort 1 is in there.

Thoughts??

Code:

#DBLOAD mobStats

#PROMPT mobStats.aggro "Is the mob aggro? Yes/No"
#PROMPT mobStats.notes "Load items or notes?"

#IF !%null( %find( @mobStats.Name, All, Name)) {#dbget %find( @mobStats.Name, All, Name)
#sa %rec
#YESNO "A duplicate mob already exists, abort?" {Yes, Abort:#dbclose #abort 1} {Keep:#say Adding}}

#SA Saving to database

#NEW All @mobStats
#dbsave
#dbreset

#SA Clearing cache
resetMobStats

#t- RetrieveMob

#SA Closing database
#dbclose
Reply with quote
shalimar
GURU


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

PostPosted: Thu Mar 29, 2018 2:56 pm   
 
The database integration tools are rather fickle.
I don't think there has been anyone to make good use of it.... which is why we have a good alternative in CMUD.

Put your database inside a json variable.

//gather the neccissary info in local variables
$mob = Mob Name
$agro = %yesno("Agro?", Yes, No)

//pull up the current value in the database, will return %null if no entry
$this = %db(@mobStats, $mob)

//update the database locally
#ADDKEY $this Agro $agro

//Then update the main database
#ADDKEY mobStats $mob $this



No way to get duplicate entries with this
_________________
Discord: Shalimarwildcat
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