Re: Rock Band Clone - Update

new topic     » goto parent     » topic index » view thread      » older message » newer message
Lone_EverGreen_Ranger said...

Below I have started on a database. I am posting a rough draft here to see if I am doing it right. Any help, I'd appeircate.

Yeah, that needs rewriting. Get into the habit of saving the result codes from db_open etc so you can perform >1 test on them and optionally display the error code in a message.

You want to try and open the database, and if it does not exist, then try and create it, not the other way round. Below is an unaltered copy of the Edita db routine. (As an example only, there is code here that you certainly won't need.)

procedure initEditaEdb() 
-- 
-- open/create the edita database 
-- 
sequence tlist 
object exh 
integer errCode 
sequence Fkey 
 
    errCode = db_open(initialcurrentdir&editaEDB,DB_LOCK_EXCLUSIVE) 
    if errCode!=DB_OK then 
        if errCode = DB_LOCK_FAIL then 
            void = proemh("Error","edita.edb locked, aborting",0)  abort(0) 
        elsif db_create(initialcurrentdir&editaEDB,DB_LOCK_EXCLUSIVE)!=DB_OK then 
            void = proemh("Error","error creating edita.edb",0)  ?9/0 
        end if 
    end if 
    isOpen = 1 
 
    tlist = db_table_list() 
    for i=1 to length(Tset) do 
        if not find(Tset[i],tlist) then 
            if i=1 then --"version" not present; delete the lot. (pre 0.2.0) 
                for j=1 to length(tlist) do 
                    db_delete_table(tlist[j]) 
                end for 
                tlist = {} 
            end if 
            if db_create_table(Tset[i])!=DB_OK then 
                DBfatal("error creating "&Tset[i]&" table",CRASHALWAYS) 
            elsif i=1 then 
--              if db_insert(1,{0,2,0})!=DB_OK then 
                if db_insert(1,{0,3,3})!=DB_OK then 
                    DBfatal("error inserting version record",CRASHALWAYS) 
                end if 
            end if 
        end if 
    end for 
 
    -- 
    -- get the version 
    -- 
    SelectTable(Tversion) 
    dbversion = db_record_data(1) 
    if compare(dbversion,{0,3,3})<0 then 
        -- 0.2.0 (pre 0.3.3/usegpp) 
        needVedb = 1 
        -- (Tversion is [eventually] set to {0,3,3} by vedb.exw) 
    end if 
    -- 
    -- Plug in the elng_xxx.exh file for automatic builtin load... 
    -- 
    exh = getexhname() 
    if sequence(exh) then 
        void = logFile(exh[1],exh[2],0) -- ie add to background task list blink) 
    end if 
 
    -- 
    -- Load the default macros now 
    --  (A macro saved as eg "F7default" [by editing the top box] will load as 
    --   the default for F7, whereas "F7" is "this session only". Note that it 
    --   handles multiple macros starting F7 alphabetically, so if you defined 
    --   both "F7default" and "F7zzz", the latter would override the former. 
    --   Of course macros can hold something named eg "paste and find next", 
    --   which will only be available after manually assigning it to a key.) 
    -- 
    MacroKeys = repeat({},4) 
    SelectTable(Tmacros) 
    for i=1 to db_table_size() do 
        Fkey = db_record_key(i) 
        if length(Fkey)>2 then 
            if Fkey[1]>'F' then exit end if 
            if Fkey[1]='F' then 
                if Fkey[2]>'9' then exit end if 
                if Fkey[2]>='6' then 
                    MacroKeys[Fkey[2]-'5'] = db_record_data(i) 
                end if 
            end if 
        end if 
    end for 
    DBclose() 
 
end procedure 

HTH, Pete

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu