Forums

OverviewFelgo 2 Support (Qt 5) › Issue with WebStorage callback

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #16319

    Kool

    Hi All,

    The WebStorage does not seem to call the callback provided as a parameter. Could it be an issue with how I provide the function callback as a parameter?

    Minimal example:

    import Felgo 3.0
    import QtQuick 2.0
    
    GameWindow {
        id: gameWindow
        activeScene: scene
        screenWidth: 960
        screenHeight: 640
    
        Scene {
            id: scene
    
            width: 480
            height: 320
    
            WebStorage {
                id: storage
            }
    
            function theCallback() {
                console.debug("Called back")
            }
        }
    
    
        Component.onCompleted: {
            storage.setValue("someValue", 0.0, scene.theCallback)
            console.debug("someValue", storage.getValue("someValue"))
        }
    }
    

     

    #16323

    G√ľnther
    Felgo Team

    Hi,

    we just had a closer look:
    Unfortunately the callback feature of setValue is broken at the moment – we will provide a fix with one of the next Felgo updates!

    Thanks for reporting the issue!

    Best,
    GT

    #16324

    Kool

    Hi Gunther,
    Thanks for looking into it. Could you suggest a work around to the following problem:

    • In my main menu scene, I have a ListView with a ListModel that shows level meta data such as “performance score” , “unlocked”, “completed”
    • The ListModel initialises with default values for all – but these values are updated with data from WebStorage
    • After the user completes a level, GameScene updates the level meta data in WebStorage
    • I needed the callback to refresh the ListModel above with the new WebStorage data

    Here is a minimal example:

    import Felgo 3.0
    import QtQuick 2.0
    
    GameWindow {
        id: gameWindow
        activeScene: scene
        screenWidth: 960
        screenHeight: 640
    
        Scene {
            id: scene
    
            width: 480
            height: 320
    
            WebStorage {
                id: storage
            }
    
            ListModel {
                id: model
                ListElement {name: "Level 1"; value: 50}
            }
    
            ListView {
                anchors.centerIn: parent
                model: model
                delegate: Item {
                    width: parent.width
                    height: 50
    
                    Text {
                        anchors.centerIn: parent
                        text: value
                    }
                }
            }
    
            function updateModel() {
                for (var ii = 0; ii < model.count; ++ii)
                {
                    var name = model.get(ii).name
                    var score = storage.getValue(name)
                    model.setProperty(ii, "value", score)
                }
            }
    
            Component.onCompleted: updateModel() // update model with storage data as soon as possible
        }
    
        Component.onCompleted: {
            // this actually takes place in my GameScene after a level finishes
            // and I simulate this here
    
            storage.setValue("Level 1", 50, scene.updateModel)
        }
    }

     

    (it might not compile/run – I wrote this in a text editor as I don’t have QtCreator on hand)

    As the callback mechanism doesn’t work, the model does not get updated. Is there a work around and hopefully better way to keep the ListModel and WebStorage in sync?

    #16326

    Christian
    Felgo Team

    Hi,

    the stored value is available immediatelly after you call setValue(), so you don’t need a callback for updating the model.

    If there is a write conflict (which only happens if the same key is written to from another device of the same user, you can use the onWriteConflict signal handler. You can also use the onWriteValueFinished signal handler, but it usually is better to immediatelly update your model after a setValue call, so users see the changed value immediatelly.

    Cheers, Chris

Viewing 4 posts - 1 through 4 (of 4 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support