0

I'm creating a Facebook leaderboard but I have some problems when I update it. When I update the facebook score and then open the leaderboard, it shows me the old score. If I close the game and I oped the game again, it shows the correct leaderboards. What am I doing wrong?

Here the code:

function fClassificaFb(event)
if event.phase == "began" then        
    bpClassificaFb.isVisible = true
end
if event.phase == "moved" then
    bpClassificaFb.isVisible = false
end
if event.phase == "ended" then
    bpClassificaFb.isVisible = false
    fbAggiornaClassifica()
    timer.performWithDelay(150, fbVisualizzaClassifica, 1)
end
end

function fbVisualizzaClassifica(event)
    local status = network.getConnectionStatus()
    if status.isConnected then
        facebook.login(appID, fbListener)
    else
        fbAlert = native.showAlert("Errore di connessione", "Non è stata rilevata alcuna connessione a Internet.", {"Annulla", "Riprova"}, fbReLogin)
    end
end

function fbAggiornaClassifica()
    local status = network.getConnectionStatus()
    if status.isConnected then
        facebook.login(appID, fbListenerAggiorna)
    else
        fbAlertAggiorna = native.showAlert("Errore di connessione", "Non è stata rilevata alcuna connessione a Internet.", {"Annulla", "Riprova"}, fbReLoginAggiorna)
    end
end

function fbListener(event)
    if "session" == event.type then
        if "login" == event.phase then
            access_token = event.token
            facebook.request(appID.."/scores")
        end
    elseif "request" == event.type then
        local response = json.decode(event.response)
        myData.dataFriends = response.data
        storyboard.gotoScene("classifica_facebook")
    end
end

function fbListenerAggiorna(event)
    if "session" == event.type then
        if "login" == event.phase then
            access_token  = event.token
                if storyboard.state.punteggio > myTable.highScore then
                    myTable.highScore = storyboard.state.punteggio
                end
                loadsave.saveTable(myTable, "myTable.json")
                local attachment = {
                    score = tostring(myTable.highScore)
                }
                facebook.request("me/scores" , "POST", attachment)
        elseif "request" == event.type then
        end
    end
end
greatwolf
  • 20,287
  • 13
  • 71
  • 105
Nick21
  • 107
  • 2
  • 10

1 Answers1

1

I had the same problem. I've found a solution by calling the facebook_login function again in a new leaderboard_refresh function and copied the same code I used to create the leaderboard into the true response(or success) part of the login function. Now my app is showing the change in the leaderboard without reloading the whole page.
The app is purely javascript and the function names are not default. Its just the idea https://apps.facebook.com/bestclicker/

TorNadO
  • 151
  • 1
  • 6