0
votes

I am using twitter API to post highscores and it seems to be collecting the score variable correctly however, its not getting the highscore value on the turn that they played.

example: I start the game for first time and my highscore is 0. I get 20 on game over and want to tweet it but my tweet displays 0. on next play through it shows 20.

So its basically behind by 1 turn each time and displays the previous highscore. I have a feeling its a basic error but i can't see, to get around it.

I have two files that save my scores for leaderboards etc.

local scoring = require("helpers.scoring")
local utils = require("helpers.globals")

function scene:createScene( event )
local group = self.view

utils.loadHighscoreInfo()

-- Gameover --

if miles > utils.highscore then 
   utils.highscore = miles
   utils.saveHighscoreInfo()
   scoring.setHighScore( utils.highscore, utils.leaderboard )  
end

-- Twitter set up --

local options = {
    message = " I scored "  .. utils.highscore ..  " Miles ",
    listener = tweetCallback
}

function tweetCallback( event )
   if ( event.action == "cancelled" ) then
      print( "User cancelled" )
   else
      native.showPopup( "twitter", options )
      print( "Thanks for the tweet!" )
   end
end
1

1 Answers

1
votes

Update the options message before handling the tweet.

local options = {
    message = " I scored "  .. utils.highscore ..  " Miles ",
    listener = tweetCallback
}

This doesn't update dynamically as utils.highscore changes, it takes a snapshot of the value at the time you declare it (first run through each game). So you simply have to update it when the game is over using

options.message = "I scored" .. utils.highscore .. " Miles "