English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 07 June 2014, 21:08   #1
Havie
Registered User
 
Join Date: Mar 2012
Location: UK
Posts: 454
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.
Havie is offline  
Old 07 June 2014, 22:11   #2
Graham Humphrey
Moderator
Graham Humphrey's Avatar
 
Join Date: Jul 2004
Location: Norwich, Norfolk, UK
Age: 33
Posts: 11,061
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
Graham Humphrey is offline  
Old 07 June 2014, 22:28   #3
Havie
Registered User
 
Join Date: Mar 2012
Location: UK
Posts: 454
Thanks Graham - this looks very helpful.
Havie is offline  
Old 08 June 2014, 12:35   #4
Havie
Registered User
 
Join Date: Mar 2012
Location: UK
Posts: 454
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!
Havie is offline  
Old 08 June 2014, 13:28   #5
Graham Humphrey
Moderator
Graham Humphrey's Avatar
 
Join Date: Jul 2004
Location: Norwich, Norfolk, UK
Age: 33
Posts: 11,061
Excellent - really glad you got it to work
Graham Humphrey is offline  
Old 08 June 2014, 14:17   #6
Havie
Registered User
 
Join Date: Mar 2012
Location: UK
Posts: 454
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.
Havie is offline  
Old 08 June 2014, 18:34   #7
Ze Emulatron
Registered User

 
Join Date: Nov 2010
Location: Invercargill, New Zealand
Posts: 176
Quote:
Originally Posted by Havie View Post
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 ?
Ze Emulatron is offline  
Old 08 June 2014, 19:17   #8
Havie
Registered User
 
Join Date: Mar 2012
Location: UK
Posts: 454
That's a good question? Have no idea what would happen. :-|
Havie is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Blitz basic 2 Help Havie Coders. Blitz Basic 30 08 September 2013 10:15
Minskies Furballs CD32 - highscore saving patch needed! Heavy Stylus support.Games 1 20 August 2008 02:54
blitz basic petza request.Apps 11 08 April 2007 02:49
Blitz Basic 2 anyone? jobro request.Apps 12 28 November 2005 19:15
Blitz Basic 2 LaundroMat Retrogaming General Discussion 5 24 July 2001 09:10

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 19:08.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Page generated in 0.07417 seconds with 13 queries