1

I want to use a local database file such as question database for my quiz game. I can't find any tutorial on official cocos creator site or forums. In c++ already solved the problem
Use database (such as sqlite) with cocos2d-x
But I want to use it with below javascript, which is the default script in Cocos creator

cc.Class({
extends: cc.Component,

properties: {
    // foo: {
    //    default: null,      // The default value will be used only when the component attaching
    //                           to a node for the first time
    //    url: cc.Texture2D,  // optional, default is typeof default
    //    serializable: true, // optional, default is true
    //    visible: true,      // optional, default is true
    //    displayName: 'Foo', // optional
    //    readonly: false,    // optional, default is false
    // },
    // ...
},

// use this for initialization
onLoad: function () {

},

onbuttnclick: function(){
    //var test = new cc.Scene('test');
    //cc.director.pushScene(test);
    cc.director.loadScene('helloworld');
    //cc.director.popScene();
},

// called every frame, uncomment this function to activate update callback
// update: function (dt) {

// },
});

I need a solution in javascript because I am poor in c++

1 Answer 1

1

in cocoscreator it have local saved api like h5 localstorage.set get parameter is key value and key i forgot the api but the point is that it like h5 localstorage api and it would auto use sqlite in native

Sign up to request clarification or add additional context in comments.

1 Comment

sorry adout the first command. cause i use the phone to reply without code. now i check the code that you can use it as follow:cc.sys.localStorage.setItem("key","value"); let value = cc.sys.localStorage.getItem("key"); you can storage any JSON.stringify(JSONObject); as the value in the localStorage and get it any time you restart the game if you do not delete the data file at disk in native or local cache in chrome.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.