# Do something only once within a range?

0 favourites
• 5 posts
From the Asset Store
Change the size and position of everything without calculating anything!
• I have a score, and if the player receives a 3 or 4 score (from racing laps), they get a small trophy; 5 , 6 or 7, they get a medium trophy, 8 or 9, a big trophy and 10+ a big trophy. I'm testing if a LocalStorage value is smaller than a lap, and if the value written in LocalStorage is lower than the lap, the trophy is shown. This works well, since if the player is replaying a level and they receive a lower score, it still retrieves and shows their highest won trophy ever for the level. When the get a higher lap than is saved in LocalStorage, it writes the higher score to localstorage and shows the new, bigger trophy. I also have a failsafe wheby is the the LocalStorage key doesn't exist, it writes the current lap to it regardless.

Now, the problem is, I can't think of how to play a "tadah" sound the FIRST time the player wins the trophy. It has a tendency whatever I write to play the "tadah" sound upon retrieving the score from LocalStorage and displaying the trophy that has been won in the past. Any clue what kind of LapCount/LocalStorageValue test I would have to perform to make sure the "tadah" sound only plays the first time the play wins the trophy?

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• If you would store also the "trophy size" to every level it should be solved.

If trophy is bigger than the stored one = Tada

Edit: you also could look at the stored score/time/lap because you know which trophy he has and so you could also check.... (but my first suggestion is simpler)

• If you would store also the "trophy size" to every level it should be solved.

If trophy is bigger than the stored one = Tada

Edit: you also could look at the stored score/time/lap because you know which trophy he has and so you could also check.... (but my first suggestion is simpler)

Thanks, I actually tried that first method after I posted this but it also didn't work, I think I might need to try again and make sure the lap numbers are being reported properly...

• GameEnded

curent score >localstorage highscore

set localstorage highscore to score