English Amiga Board

English Amiga Board (http://eab.abime.net/index.php)
-   Coders. General (http://eab.abime.net/forumdisplay.php?f=37)
-   -   Saving Highscore to Disk in Blitz Basic (http://eab.abime.net/showthread.php?t=73996)

Havie 07 June 2014 20:08

Saving Highscore to Disk in Blitz Basic
 
Hi - my Blitz Basic Flappy Bird clone is almost complete and I would like to be able to save a highscore to disk. Have had a look through the documentation but as usual Blitz is a complete mystery.

I guess I need to open files and put values in them but really haven' a clue. Any help would be much appreciated.

Graham Humphrey 07 June 2014 21:11

This is how I stored my high scores in my game Downfall - full source is on the site if you wish to take a peek :)

I set my scores to be stored in an array (holding 20 entries) which contained the name and the score of the player. The save routine only saved it if the scores had changed since the last load when the game was quit so you might not want to do it exactly the same way but hopefully it gives you a bit of an idea.

Code:

.loadhighscores

If OpenFile(0,"Data/downfall.highs")=-1 ; open our file if it exists
 For n=0 To 19
  Fields 0,highs(n)\name,highs(n)\score ; read all array data
 Next n
EndIf
Get 0,0 ; transfer data to array
CloseFile 0

Return

.savehighscores

AMIGA
If chg=1  ; If highscore file has changed
 dummy=OpenFile(0,"Data/downfall.highs") ; create new file, or overwrite existing one
 For n=0 To 19
  Fields 0,highs(n)\name,highs(n)\score  ; take all highscore array data
 Next n
 Put 0,0 ; write array data to our file
 CloseFile 0
EndIf

Return


Havie 07 June 2014 21:28

Thanks Graham - this looks very helpful.

Havie 08 June 2014 11:35

Amazing - took your code and modified it like this and it worked first time! Simples!!!

Quote:

(beginning of game)
If OpenFile (0,"highscoret.dat")=-1
Fields 0,highold
End If
Get 0,0
CloseFile 0
high=highold

(at end of game)
If high>highold
dummy= OpenFile (0,"highscoret.dat")=-1
Fields 0,high
Put 0,0
CloseFile 0
End If

End
Thank you so much!

Graham Humphrey 08 June 2014 12:28

Excellent - really glad you got it to work :)

Havie 08 June 2014 13:17

We should try and get all the Blitz Coders to pool their knowledge as it does load's but documentation and examples are very scarce. You really need to persevere to get anywhere.

Ze Emulatron 08 June 2014 17:34

Quote:

Originally Posted by Havie (Post 958499)
Amazing - took your code and modified it like this and it worked first time! Simples!!!

Quote:

(beginning of game)
If OpenFile (0,"highscoret.dat")=-1
Fields 0,highold
End If
Get 0,0
CloseFile 0
high=highold

(at end of game)
If high>highold
dummy= OpenFile (0,"highscoret.dat")=-1
Fields 0,high
Put 0,0
CloseFile 0
End If

End

Thank you so much!

What happens if the executable it is run from a write protected ADF or disk ?

Havie 08 June 2014 18:17

That's a good question? Have no idea what would happen. :-|


All times are GMT +2. The time now is 13:14.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.

Page generated in 0.04226 seconds with 11 queries