2014-02-26 15 views
0

我正在創建Facebook排行榜,但在更新它時遇到一些問題。當我更新facebook分數然後打開排行榜時,它會顯示舊分數。如果我關閉遊戲並再次打開遊戲,它會顯示正確的排行榜。我究竟做錯了什麼?Facebook圖表排行榜不會立即更新

下面的代碼:

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 

回答

1

我有同樣的問題。我找到了一個解決方案,通過在新的leaderboard_refresh函數中再次調用facebook_login函數,並將用於創建排行榜的相同代碼複製到登錄函數的真實響應(或成功)部分中。現在我的應用程序正在顯示排行榜中的更改,無需重新加載整個頁面。
該應用程序純粹是JavaScript,而函數名稱不是默認值。它只是想法 https://apps.facebook.com/bestclicker/