Hey all,
I've been trying to make a database with the DarkData addon for a project that is intended to be a small online RPG. Hence, the databases will be used for such things as character stats, inventory contents, and item stats.
In trying to learn the features of DarkData, I made three projects to create, edit and search a database respectively.
However, when I try to search the Database, it always returns blank fields. Despite the .dat file certainly containing data.
Here's my code:
Create Database:
Rem Project: CreateDatabases
Rem Created: Monday, July 19, 2010
Rem ***** Main Source File *****
// Create Database
DataBaseName$="Login_Database.dat"
Index#=1
IndexName$="Login_Index.dat"
DFS Create 1,DataBaseName$,1
// Create Database Fields
DFS Add Field 1,"String 5 as Account_ID"
DFS Add Field 1,"String 12 as Username"
DFS Add Field 1,"String 12 as Password"
DFS Add Field 1,"String 10 as Date_Created"
DFS Add Field 1,"String 3 as Admin_Status"
DFS Finish 1
DFS Save 1,1
KFS Create 2, "Account_ID.kfs", 5, 1, 0
KFS Create 3, "Username.kfs", 12, 1, 0
KFS Create 4, "Date_Created.kfs", 10, 0, 0
Populate Database:
Rem Project: PopulateDatabases
Rem Created: Monday, July 19, 2010
Rem ***** Main Source File *****
// Open Database
DFS Open 1,"media\Login_Database.dat"
// Input Method
InputMethod:
print ""
input "Username: ", Username$
print ""
input "Password: ", Password$
print ""
input "Admin_Status: ", Admin_Status$
PreviousAccount_ID# = 0
PreviousAccount_ID# = (DFS Get(1,"Account_ID"))
str$(PreviousAccount_ID# + 1) = Account_ID$
Date_Created$=Get Date$()
record = DFS Add (1)
DFS Put 1, "Account_ID", Account_ID$
DFS Put 1, "Username", Username$
DFS Put 1, "Password", Password$
DFS Put 1, "Date_Created", Date_Created$
DFS Put 1, "Admin_Status", Admin_Status$
KFS Create 2, "Account_ID.kfs", 5, 1, 0
KFS Create 3, "Username.kfs", 12, 1, 0
KFS Create 4, "Created.kfs", 10, 0, 0
KFS Add 2, Account_ID$, record
KFS Close 2
KFS Add 3, Username$, record
KFS Close 3
KFS Add 4, Date_Created$, record
KFS Close 4
print ""
print "Press Ctrl to add another entry."
print "Press Shift to save database entries and exit."
DFS Save 1,record
wait key
if controlkey()=1
cls
goto InputMethod
ENDIF
if shiftkey()=1
end
ENDIF
Search Database:
Rem Project: SearchDatabase
Rem Created: Monday, July 19, 2010
Rem ***** Main Source File *****
DFS Open 1,"media\Login_Database.dat"
KFS Open 2, "media\Account_ID.kfs"
KFS Open 3, "media\Created.kfs"
KFS Open 4, "media\Username.kfs"
print "Do you wish to search for an Account ID, Date Created, or Username?"
input "", selection$
input "Input search keyword: ", keyword$
if selection$="Account ID"
recnum = KFS Find (2, keyword$)
print "Account ID is keyed to record: ", recnum
print ""
input "Print entire record? [Y/N]", printrecord$
if printrecord$ = "Y"
DFS Load 1, recnum
Account_ID$ = DFS Get$(1,"Account_ID")
Username$ = DFS Get$(1,"Username")
Password$ = DFS Get$(1,"Password")
Date_Created$ = DFS Get$(1,"Date_Created")
Admin_Status$ = DFS Get$(1,"Admin_Status")
else end
endif
endif
print "Account_ID: " + Account_ID$
print "Username: " + Username$
print "Password: " + Password$
print "Date Created: " + Date_Created$
print "Admin Status: " + Admin_Status$
wait 5000
print "Press Enter to Exit."
if returnkey()=1 :
dfs close 1
kfs close 2
kfs close 3
kfs close 4
end
endif
The database project files all draw from the same media directory in which the .dat and index files are located.
Please take a look at my code, and see if I am making any obvious mistakes?
Thanks,
Vampire2948,