Database Error



  • HI, I'm creating a RPG game on qt quick with a save game feature. In order for me to do that is to have a database to store in which level the player have finished. But when I am trying to run the program. It has an error "cannot find database" or reference error. Please help me and thank you in advance! Here is my code.

    Database.js

    @function getGameBase(){
    return openDatabaseSync("gameBase", "1.0", "StorageDatabase", 50);
    }

    function initialize() {
    var db = getGamebase();
    db.transaction(
    function(tx) {
    tx.executeSql('CREATE TABLE IF NOT EXISTS game(gameNum NUMBER UNIQUE,money NUMBER,str NUMBER,int NUMBER,def NUMBER,level NUMBER)');

            //initialize start up value
                    for(i=0; i <=3; i++ )
                    {
                        tx.executeSql('INSERT INTO game VALUES (?, 100,5,3,5,0)', [i])
                    }
    
                });
    

    }

    function getMoney(gameIter){
    var db = getGameBase();

    db.transaction(function(tx){
                       var rs = tx.executeSql('SELECT money FROM game WHERE gameNum=?;', [gameIter])}
                       )
    return rs
    

    }

    function getLevel(gameIter){
    var db = getGameBase();

    db.transaction(function(tx){
                       var rs = tx.executeSql('SELECT level FROM game WHERE gameNum=?;', [gameIter])}
                       )
    return rs
    

    }

    @

    Main Qml
    @import QtQuick 1.1
    import com.nokia.symbian 1.1
    import "database.js" as Storage

    Page{
    id:mainPage

    property int gameMoney
    property int tempCon
    property int tempLvl
    property int resCont
    
    
    function retMoney(iter)
    {
        tempCon = Storage.getMoney
        return tempCon
    }
    
    function retLevel(a)
    {
        tempLvl = Storage.getLevel(a)
        return tempLvl
    }
    
    Image
    {   id: background
        width:parent.width ; height: parent.height
        source:"image/woodBg.jpg"
    
        Row
        {   x:35 ;y:20
    
            Image
            {   id:menu1
                source:"image/mainTile.png"
    
                MouseArea{
                    id:msArea1
                    anchors.fill: parent
                }
    
                Text
                {id:money1
                 x:20 ; y:40}
    
                Text
                {id:lvl1;
                 x:20 ; y:80}
    
                Button
                {
                    id:mbt1
                    x:40; y:250
                    text:"New Game"
                }
            }
    
            Image
            {   id:menu2
                source:"image/mainTile.png"
    
                MouseArea{
                    id:msArea2
    
                }
    
                Text
                {id:money2;text:"Money: "
                    x:20 ; y:40}
    
                Text
                {id:lvl2; text:"Level: "
                 x:20 ; y:80}
    
                Button
                {
                    id:mbt2
                    x:40; y:250
                    text:"New Game"
                }
            }
    
            Image
            {   id:menu3
                source:"image/mainTile.png"
    
                MouseArea{
                    id:msArea3
                }
    
                Text
                {id:money3;
    
                 text:"Money: "
                    x:20 ; y:40}
    
                Text
                {id:lvl3; text:"Level: "
                 x:20 ; y:80}
    
                Button
                {
                    id:mbt3
                    x:40; y:250
                    text:"New Game"
    
                }
            }
    
            Component.onCompleted: {
                Storage.getGameBase();
                Storage.initialize();
                money1.text = "Money: \n" + Storage.getMoney('1')
        }
    }
    

    }
    }

    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.