Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
adamwalker
Apprentice


Joined: 12 Mar 2005
Posts: 195

PostPosted: Sat Jul 16, 2005 9:26 am   

Accessing databases
 
basically what I want seems quite simple but I cant work out the database side of it.. i need a little help...

I have a trigger of...

potion64 Health Sips: 201
potion65 Health Sips: 27

What I want is that information to be automatically to a database

So fields would be

Type = HEALTH
number = 64
Location = hands (i would enter this manually)
full = 1 (does have sips in it)
---

then when I run an alias... for example. RUNHEALTH

it would get health potion from sack that isnt empty. then put the old bottle into my sack, and flag full = 0, and set location to sack.

it seems quite easy but the database side is just going over my head

----

basically what i want in the end is a system that can effortlessly switch potions using a database so im not holding many in my hands

----

i know this is quite a big request so i dont expect someone to write it for me.. but some help to point me in the right direction would be great

thankyou for your time
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat Jul 16, 2005 7:28 pm   
 
The following commands should be useful to you:

1)#DBLOAD, #DBSAVE, #DBCLOSE -- these commands open, close, and save your database file. Standard practice is to do these things every time you use the database file, so that it's not just sitting there wasting memory. Thus, in your trigger, the code would start looking like this:

#DBLOAD databasename
(stuff to do)
#DBSAVE
#DBCLOSE

2)#QUERY/#FIND will look in the database for a matching record. If found, the %rec system variable will be loaded with the first matching record; if not, I believe it gets set to %null. You can use this to see if the potion is already in the database. If it's not in the database, you can add a new record using #NEW. If it's already there, you can use #DBPUT to update that record. Your code will look something like this now:

#DBLOAD databasename
#QUERY HEALTH (stuff to match from the trigger pattern)
#IF (%null(%rec)) {#NOOP new potion} {#noop existing potion}
#DBSAVE
#DBCLOSE

3)#DBGET will allow you to retrieve a specific record. #DBFIRST retrieves the very first record, #DBLAST the very last one, and #DBNEXT/#DBPREV step through each record one-by-one until either first/last is reached (in that case, the %rec system variable is set to %null rather than looping back to the other end of the database). Another command which might prove useful for your database system is #DBDELETE. This command will allow you to delete records which represent empty potions. It's rarely needed, in my opinion, unless items are being phased out.
_________________
EDIT: I didn't like my old signature
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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