Re: Rock Band Clone - Update
- Posted by DerekParnell (admin) Nov 30, 2011
- 1325 views
Lone_EverGreen_Ranger said...
The only thing is how would I make it so that you can add custom songs?
I just made up some data to show as an example. You would have to work out what fields you need in a SONG record and get the data to populate those fields from some external place, such as someone typing them into the application.
You could then make the 'insert' code into a function that you passed the SONG record to. The unique record key that I used is just generated from some fields whose data will both uniquely identify a particular song and will never change for that song. For this example I just used a simple atom to hold the hash value (record key) and that should be adequate for songs but to make sure you could change the generation function to ...
function add_new_record(sequence TableName, sequence RecordFields, integer IDFldLow, integer IDFldHigh) object record_key integer record_id integer dbres dbres = db_select_table(TableName) if dbres != DB_OK then return {1, "Table not found", dbres} end if record_key = RecordFields[IDFldLow..IDFldHigh] record_key = hash(record_key, TableName) & hash(record_key, record_key) record_id = db_find_key(record_key) if record_id < 0 then dbres = db_insert(record_key, RecordFields) if dbres != DB_OK then return {2, "DB Insert failed", dbres} else return {0, -record_id} -- insert success, return new record's id. end if else return {3, record_id} -- already in db, return record's id. end if end function object SongData sequence res while 1 do SongData = Get_Song_Details() if atom(SongData) then exit end if res = add_new_record(SongTable, SongData, 1, 3) if res[1] != 0 then Handle_Error(res, SongTable, SongData) end if end while