Stop score (integer) going below zero

bluellamabluellama Member, PRO Posts: 27

Hello,

I have multiple actors that affect my game score attribute by +10, +50 and -50.
However, if the player collides with the -50 actor before their score is high enough, it results in a score below zero.

I have currently changed my game score attribute to an index instead of integer to avoid this, however that seems to be causing other issues with my code.

I would like to keep it as an integer, so how do I stop it from showing a negative score?

Comments

  • Case86Case86 Member, PRO Posts: 35

    u could do it with :
    whenscore < 0. change score to 0.

    but i'd go for Index, it should work and simpeler.

  • bluellamabluellama Member, PRO Posts: 27

    Thanks Case86, I thought about trying whenscore <0 - but would this mean the display text would show the number changing from negative to zero if there was a delay in the code?

    Index is what I have currently done, but my game seems to freeze when my code tries to update my high score (an integer in a table) from the game score as an index. I've assumed it was because I was comparing an index to an integer? But not entirely sure. I've been trialling that way because my original high score was also an index attribute and it just wasn't working. It would update the score sometimes, not always, and would sometimes pull a completely random number for the high score instead of referring to the game score.

    Maybe I need to go back to using attributes for both and troubleshooting that, just wanted to see if there was another way around the problem first?

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited August 2015

    the simpilest solution and slimest method code wise is to switch to an index attribute as it won't produce negative numbers. Just change your highscore to an index in the table and see.

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2015

    Add a condition to the -50 rule, that says When score > 0.

  • bluellamabluellama Member, PRO Posts: 27

    Thanks guys. I've had another suggestion to try the function: max(0,game.score)
    I think this will help, as it should tell the game to either reference zero or the score if above zero.

    Using a condition when score>0 would work in some cases, but if the player already had 10 points, then it would end up -40, so it wouldn't always work. I appreciate the suggestions though!

    I wanted to change highscore to index, however the table doesn't include this option at all :(

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Yes, using change attribute game.score to max(0,game.score-50) should work fine.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SocksSocks London, UK.Member Posts: 12,822

    @bluellama said:
    Using a condition when score>0 would work in some cases, but if the player already had 10 points, then it would end up -40, so it wouldn't always work.

    Good point !! :smile: I didn't spot the +10 scoring possibility.

    I'd go with the max(0,XX) option.

Sign In or Register to comment.