我正在创建一个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
答案 0 :(得分:1)
我遇到了同样的问题。我通过在新的 leaderboard_refresh 函数中再次调用 facebook_login 函数找到了解决方案,并将用于创建排行榜的相同代码复制到真实的响应中(或成功)登录功能的一部分。现在我的应用程序在没有重新加载整个页面的情况下显示排行榜中的更改。
该应用程序纯粹是javascript,函数名称不是默认值。这只是想法
https://apps.facebook.com/bestclicker/