Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Need some help implementing Leaderboard in FB Instant Game — Gideros Forum

Need some help implementing Leaderboard in FB Instant Game

sam_msam_m Member
edited August 2019 in General questions
I've having trouble getting leaderboard to work in FB Instant.
This is the code I'm using upon finishing a level to save the score. But I'm getting the error -

"LuaPlugins_/FBInstant.lua:384: attempt to call method 'gsub' (a nil value)
stack traceback:
_LuaPlugins_/FBInstant.lua:384: in function 'escapeString'
_LuaPlugins_/FBInstant.lua:447: in function 'setScoreAsync'
GameManager.lua:502: in function '?'
_LuaPlugins_/FBInstant.lua:555: in function <_LuaPlugins_/FBInstant.lua:553>"

The code I'm using is -
                if mydata.FBInstantAPI == true then
                    mydata.FBInstant.getLeaderboardAsync("my_leaderboard", function(result,error)
                            if result then
                                print("score ok",entry)
                                for key,val in pairs(entry.entry) do
                                    local text = TextField.new(mydata.font1, "0")
                                    text:setPosition(20, 20)
                                    text:setText(key.." "..tostring(val))
Any and all help deeply appreciated. Thanks.


  • hgy29hgy29 Maintainer
    Accepted Answer
    IIRC the second parameter to setScoreAsync must be a string (json), not directly a table

    Likes: Apollo14, sam_m

    +1 -1 (+2 / -0 )Share on Facebook
  • sam_msam_m Member
    edited August 2019
    @hgy29 Thank you so much for your reply. With your help, the code now works.

    Now for what I'm sure is a very stupid question. How do I put variables in the string?
    As in this works - '{race: "elf", level: 3}'

    I'd also like to make this work - {level: mydata.levelID}'
  • hgy29hgy29 Maintainer
    edited August 2019 Accepted Answer
    You can use several ways:
    -- Using concatenation:
    local payload=[[{race: "]]..playerRace..[[", level: ]]..playerLevel..[[}]]
    -- Using string.format:
    local payload=([[{race: "%s", level: %d}]]):format(playerRace,playerLevel)
    -- Using json encode
    require "json"
    local playerData={ race=playerRace, level=playerLevel}
    local payload=json.encode(playerData)
    +1 -1 (+3 / -0 )Share on Facebook
  • @hgy29 It works. Thank you so much.

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.