Jump to content

Photo

Saving Highscore


4 replies to this topic

#1 Coolcrab OFFLINE  

Coolcrab

    Moonsweeper

  • 400 posts
  • Location:Stockholm

Posted Sat Sep 29, 2018 9:26 AM

I just noticed that my Highscore saving script does not work, mostly because it looks at the 3 score groups separately.

 if _sc1 > _a then __New_High_Score

 if _sc2 > _b then __New_High_Score

 if _sc3 > _c then __New_High_Score

 goto __Skip_High_Score

__New_High_Score
 rem store high score
 _a = _sc1 : _b = _sc2 : _c = _sc3


__Skip_High_Score

WIth this script 000085 will be seen as a high score compared to 002040 because 85 > 40. 

Is there a simple way around this that used 16 bytes or less? :P



#2 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 28,801 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Sat Sep 29, 2018 2:53 PM

All I know is that supercat and Nukey Shay went over and over and over this code until it was about as perfect as you can get:

 

Saving a High Score  (by supercat and Nukey Shay)



#3 Karl G ONLINE  

Karl G

    Dragonstomper

  • 610 posts

Posted Sat Sep 29, 2018 3:13 PM

If in your source, _sc1 is set to score, _sc2 is set to score+1 and _sc3 is set to score+3, then it would first checks the variable holding the 100 thousands and ten thousands digits, then the variable holding the thousands and hundreds digits, then the variable holding the tens and ones digits.  In your example, 002040 would register as a new high score over 000085 because _sc2 would be compared before _sc3, and 20 > 0.  So, the code above in theory should work.

 

My guess would be there is somewhere else you are setting or resetting the values in _a _b and _c causing it to not work as you expect.



#4 Coolcrab OFFLINE  

Coolcrab

    Moonsweeper

  • Topic Starter
  • 400 posts
  • Location:Stockholm

Posted Sun Sep 30, 2018 2:03 AM

All I know is that supercat and Nukey Shay went over and over and over this code until it was about as perfect as you can get:

 

Saving a High Score  (by supercat and Nukey Shay)

 

Thanks!

 

It didn't fit but I change it up into this.  

 



 if _sc1 > _a then __New_High_Score
 if _sc1 < _a then __Skip_High_Score


 if _sc2 > _b then __New_High_Score
 if _sc2 < _b then __Skip_High_Score


 if _sc3 > _c then __New_High_Score else  goto __Skip_High_Score

 

If in your source, _sc1 is set to score, _sc2 is set to score+1 and _sc3 is set to score+3, then it would first checks the variable holding the 100 thousands and ten thousands digits, then the variable holding the thousands and hundreds digits, then the variable holding the tens and ones digits.  In your example, 002040 would register as a new high score over 000085 because _sc2 would be compared before _sc3, and 20 > 0.  So, the code above in theory should work.

 

My guess would be there is somewhere else you are setting or resetting the values in _a _b and _c causing it to not work as you expect.

if score is xxyyzz then sc1=xx, sc2=yy, sc3=zz right? Or is it the other way around? 

Because it can skip the first two if's in the original code if they are not larger and the get triggered on the third. The new code seems to work better, but I'm still testing.



#5 bogax OFFLINE  

bogax

    Dragonstomper

  • 782 posts

Posted Sun Sep 30, 2018 11:25 AM

I think this should work, but I don't think you can do it in less than 16 bytes

 

  dim scr0 = score
  dim scr1 = score + 1
  dim scr2 = score + 2
 
  dim hi0 = a
  dim hi1 = b
  dim hi2 = c
 
  if scr0 <= hi0 && scr1 <= hi1 && scr2 <= hi2 then skip_new_high_score
  hi0 = scr0 : hi1 = scr1 : hi2 = scr2
  
skip_new_high_score





0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users