Informacion para hacer highscore?

Hi Rob: Thanks it works!

----------THERE IS ONE LITTLE PROBLEM------------

function scene:enterScene( event )
    local group = self.view
    
    local littleBees = display.newImage (“littleBees.png”)
    littleBees.x = 28
    littleBees.y = 30
    littleBees:scale (.5, .5)
    transition.to(littleBees, {x=167, y=37, time=6000})

group:insert( littleBees )

end


I change the bees to enterScene and when I come back to the scene, it plays the transition FINE,

but the little bees are still there when I come back, now I have a DUPLICATE IMAGE of each bee on the enterScene.

I try this on the exitScene - — I was just trying to use logic

function scene:exitScene( event )
    local group = self.view
    
    if littleBees then
        littleBees:removeSelf()
        littleBees = nil
    end

end

-------------------------- but that did not work.  it seems to work only on BUTTONS, I don’t know why.

So how do I remove the little bees from that scene?

So when I come back to the same scene it will play the animation normally?

Thank you

Victor

Hi paytopwn, I follow your instrutions and I have an error:

“attempt to compare number with table”

I am really sure about this error is using the librarie that you say… but I dont know how fix it… if you can give me some help I will really apreciate it…

Thx :slight_smile:

Sorry for my english :stuck_out_tongue:

Hey jhsanchez,

Can you post your code so we can take a deeper look into it? 

Cheers! 

SURE :smiley:

On my game code:

game.lua :

– Requerimientos

local physics = require “physics”

physics.start()

require “sprite”

local storyboard = require(“storyboard”)

local scene = storyboard.newScene()

local preference = preference – cargamos fichero de preferencias

local score – puntuacion actual del jugador

– Fondo

function scene:createScene(event)

    local output = display.newText(“0”,0,0, native.systemFont, 20)

    output:setTextColor(255,255,255)

    output:setReferencePoint(display.BottomLeftReferencePoint)

    output.x = 430

    output.y = 300    

function PararReloj(esto)

    

    timer.cancel(tmr)

    transition.to( output, { time=3000, alpha=0 } )

    score = output

    maxScore = preference.getValue(“highscore”) – guardamos la puntuación máxima en maxScore

    

      if score > maxScore then – miramos si la puntuación que hemos realizado es superior al máximo guardado

              

        textoScore = display.newText("",240,175,“Helvetica”,25)

        textoScore:setTextColor(255,255,255)

        textoScore:setReferencePoint(display.BottomLeftReferencePoint)

        textoScore.text="You have a NEW RECORD (secs): "…esto

        transition.to( textoScore, { time=3000, alpha=0 } )

            preference.save{ highscore=score}

      else

        textoScore = display.newText("",240,175,“Helvetica”,25)

        textoScore:setTextColor(255,255,255)

        textoScore:setReferencePoint(display.BottomLeftReferencePoint)

        textoScore.text="Your time was (secs): "…esto

        transition.to( textoScore, { time=3000, alpha=0 } )

            preference.save{ highscore=score}

      end    

        

           

end

ON MY MAIN:

display.setStatusBar(display.HiddenStatusBar)

preference = require “preference”

preference.save{ highscore = 1} --preference highscore

local storyboard = require “storyboard”

storyboard.gotoScene(“start”)


THANK U 4 YOUR HELP :smiley:

The error apears here:

 if score > maxScore then – miramos si la puntuación que hemos realizado es superior al máximo guardado

Here is the problem:

score = output maxScore = preference.getValue("highscore")

What is “score”?   Score is a copy of a display object named output.  It is not a number.  Display objects are a table.  Most likely what you want is:

score = output.text

Hi Rob, thank you for your time… With that correctcion I have the error… “attempt to compare number with nil:confused:

You need to make sure that you are not overwriting output somewhere else that’s not the display.newText() that you’re creating a few lines above

Yeah! You have reason, thank you so much… Now I can save my local highscores :D… Now I will work on the global highscores with corona cloud… wish me luck :D!

Good luck jhsanchez :wink:

I’m glad you’ve already solved that ! 

Rob and paytopwn I have a problem with local records… the game save the records correctly when I use the app butttt… when I close the app and start over again the records has restarted… Exist some solution for this? Thank you so much for your help… Regards.

You need to save the data to a file in your app’s file system space.  I don’t know much about the library you are using to track the information, so I really can’t help too much.   There are several saving data entries in the community code.

Oh :/…

I have all the day readding the docs for the library but I dont understand whats going on…

Paytopwn… I hope you can help me.

If you’ve followed my original code you’ll see that some of the data is saved as preferences - then it’s possible that you’re overwritting on every execution of your game all the values (in other words, every time you start your game you clear all your saved scores to the initial value you have in your code). 

preference.save{ highscore = 1} --preference highscore

If that’s what you have in your main, you have no condition to check if there’s a higher score saved, and a simple solution would make an if statement to check if that highscore is greater than 1 (meaning that you’ve have saved something before). 

What Rob says about using a file instead of a preference sounds better, even though using the way you have it would be easier. 

“Programar es como conducir, cada uno lo hace como quiere” 

Si amigo, efectivamente ayer me di cuenta de ese terrible error y ya pude corregirlo :D! Muchas gracias bro, saludos :slight_smile:

Hi paytopwn, I follow your instrutions and I have an error:

“attempt to compare number with table”

I am really sure about this error is using the librarie that you say… but I dont know how fix it… if you can give me some help I will really apreciate it…

Thx :slight_smile:

Sorry for my english :stuck_out_tongue:

Hey jhsanchez,

Can you post your code so we can take a deeper look into it? 

Cheers! 

SURE :smiley:

On my game code:

game.lua :

– Requerimientos

local physics = require “physics”

physics.start()

require “sprite”

local storyboard = require(“storyboard”)

local scene = storyboard.newScene()

local preference = preference – cargamos fichero de preferencias

local score – puntuacion actual del jugador

– Fondo

function scene:createScene(event)

    local output = display.newText(“0”,0,0, native.systemFont, 20)

    output:setTextColor(255,255,255)

    output:setReferencePoint(display.BottomLeftReferencePoint)

    output.x = 430

    output.y = 300    

function PararReloj(esto)

    

    timer.cancel(tmr)

    transition.to( output, { time=3000, alpha=0 } )

    score = output

    maxScore = preference.getValue(“highscore”) – guardamos la puntuación máxima en maxScore

    

      if score > maxScore then – miramos si la puntuación que hemos realizado es superior al máximo guardado

              

        textoScore = display.newText("",240,175,“Helvetica”,25)

        textoScore:setTextColor(255,255,255)

        textoScore:setReferencePoint(display.BottomLeftReferencePoint)

        textoScore.text="You have a NEW RECORD (secs): "…esto

        transition.to( textoScore, { time=3000, alpha=0 } )

            preference.save{ highscore=score}

      else

        textoScore = display.newText("",240,175,“Helvetica”,25)

        textoScore:setTextColor(255,255,255)

        textoScore:setReferencePoint(display.BottomLeftReferencePoint)

        textoScore.text="Your time was (secs): "…esto

        transition.to( textoScore, { time=3000, alpha=0 } )

            preference.save{ highscore=score}

      end    

        

           

end

ON MY MAIN:

display.setStatusBar(display.HiddenStatusBar)

preference = require “preference”

preference.save{ highscore = 1} --preference highscore

local storyboard = require “storyboard”

storyboard.gotoScene(“start”)


THANK U 4 YOUR HELP :smiley:

The error apears here:

 if score > maxScore then – miramos si la puntuación que hemos realizado es superior al máximo guardado

Here is the problem:

score = output maxScore = preference.getValue("highscore")

What is “score”?   Score is a copy of a display object named output.  It is not a number.  Display objects are a table.  Most likely what you want is:

score = output.text