# reading writing to eeprom

#### Pommie

##### Well-Known Member
Most Helpful Member
Bert, he's using mod to get the 1000ths portion.

Mike.

#### be80be

##### Well-Known Member
OldScore = 256 mod 1000 that = 256

OldScore = 400 mod 1000 guess what that = 400

what good is any of this LOl

You should save score as what ever you want DEC 256 500 5000 what ever it is
don't think it be that high but still save it as one thing like been said

Just test the score if newScore > OldScore then save newScore Im going to bed LOL

#### Pommie

##### Well-Known Member
Most Helpful Member
Bert, he's saving the score as mS so it can be displayed with 3 decimal places. So 12345 is stored and gets displayed as 12.345 seconds.

Mike.

Last edited:

#### be80be

##### Well-Known Member
Maybe I crazy but
ms Mod 1000
ms has to be a number say 5650 that drops off 5000 and leaves 650

But why would you save score of 650
then say it 650 Mod 1000 that's 650
you now have too things that can be the same value

I see what your saying mike just looks like there is a easy way to do this

#### Pommie

##### Well-Known Member
Most Helpful Member
If the stored (saved) value is 5650 then it represents a time of 5.65(0) seconds.

Mike.

#### Pommie

##### Well-Known Member
Most Helpful Member
I showed him how to do that back in
Wow, that was ONLY 112 posts ago!

Mike.

#### tumbleweed

##### Active Member
I know, times flies!

The astute observer might have said "gee, why don't I turn that into a function so I won't have to type it over and over again and screw it up..."
Code:
// convert word in ms to secs string (ie "D.DDD")
public function format_msec(wval as word) as string(8)
result =  DecToStr(wval/1000) + "." + DecToStr((wval MOD 1000), 3)
end function
Then displaying values would be as simple as :
Code:
WriteAt(1,1,"reaction=",format_msec(OldScore), "secs")
But that was never going to happen.

#### be80be

##### Well-Known Member
In post #129 I can see that would be the way to go

But Mrdeb using mod on formatting the EE.wirte formatting the print to Lcd My point was h's mod to much LOL

The way some code that's been posted he would be saving just the same thing over never see a new score or the right score

Just save the score on close of the game in a Dec value

Then print it as you as Jerry showed.

#### granddad

##### Well-Known Member
Hey guys , club together and buy him a stopwatch and a pad of sticky notes .. while you still have your sanity ..

#### MrDEB

##### Well-Known Member
reffering to post 127, I removed the , 3) + "secs" because it didn't look right on the LCD display.
as for the FUNCTION I contemplated using it but I was having too many issues with the value of MS interacting with CURRENT_SCORE and BEST_SCORE
Have to solve one issue at a time instead of throwing more fuel on the fire.
I have the code edited down so it doesn't access the eeprom so much.
Been trying out different sections of code first before combining it all together into one.
Still waiting on new pcboards before adding a second game option.

#### tumbleweed

##### Active Member
I removed the , 3) + "secs" because it didn't look right on the LCD display
You can remove the '+ "secs"' part if you wish, but if you remove the ',3)' then the displayed value will be wrong 99% of the time.
.
as for the FUNCTION I contemplated using it but I was having too many issues with the value of MS interacting with CURRENT_SCORE and BEST_SCORE
If you add the format_msecs function shown then there will be no interaction between anything and all those problems will go away.
To display a value you would simply use 'format_msecs(put_your_variable_name_here)' in the 'WriteAt' call, something like
Code:
WriteAt(1,1,"reaction=",format_msec(CURRENT_SCORE), "secs")
WriteAt(1,1,"reaction=",format_msec(BEST_SCORE), "secs")

#### MrDEB

##### Well-Known Member
will give it a try
thanks

Loading