High score works intermittently and sometimes creates random numbers

bluellamabluellama Member, PRO Posts: 27

Hello,

I have two attributes, both are INDEX (so they can't go into negative numbers)
1. game score
2. high score

At the end of my game (when lives=0) a pause scene is activated for "game over"
On this game over scene, I have the following codes on an actor to determine the high score and display it:

When "game.game score" > "game.high score"
Change attribute "game.high score" to "game.game score"
Save attribute "game.high score" to key: "highscore"

Then I use a display text to actually display the high score.

On my game's main menu (first scene when restarting), I have an actor with:
Load key: "highscore" attribute: "game.high score"

As far as I am able to find online, this code should work, however I am finding that it only works sometimes. Other times, it either doesn't keep the most recent score, or it chooses a completely random number to display as the high score - I'm not even sure how it has come to the random number.

Can anyone shed some light or provide a different code to achieve this please?
I have triple checked that my code is EXACTLY what I have written above.

I have also already tried achieving the same result using a table, however that froze my entire game. I have posted about that separately because I'm trialing some different options to fix my overall problem and don't want to confuse.

Thanks for any help.

Comments

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    There must be errors in your code somewhere. Make sure you also have the load attribute in any other spot the game might start from. This is why it's best to use a table. If your game freezes using tables you might have a table expression written wrong this causes a crash freeze. Best to post some shots of your code.

  • bluellamabluellama Member, PRO Posts: 27

    I thought that you only needed to load attributes if the player exits the game? Is this incorrect? shouldn't the attributes remain the same between scene changes?

    Can you please also explain what you mean by "table expression"? I've taken screenshots of both codes I was attempting to work with. One for the attribute change, one for the table change. It's hard to see what's in the expression editor from the screenshot. I have kept both codes but currently have the tables turned off to avoid the freezing occuring.

    My "load attribute" is currently located on the first scene.
    My "save table" attribute is located on the same actor as the table code in the screenshot.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited August 2015

    Watch the code order be sure the update high score code is before the write to table. if they are not in the same actor move them into one actor. code in an actor fires in order top to bottom. The basis of logic building is things happen in an logical order even at 100's of a second.

  • bluellamabluellama Member, PRO Posts: 27

    Thanks for the suggestions. I think you are thinking along many of the same lines that I have been before posting this. The order is correct and they are in the same actor. Still puzzling.... I appreciate the help!

Sign In or Register to comment.