Ooops
November 25, 2020, 08:02:32 AM

Author Topic: [bb] File Saving and Loading by Q [ 1+ years ago ]  (Read 560 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] File Saving and Loading by Q [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
Title : File Saving and Loading
Author : Q
Posted : 1+ years ago

Description : I hope this makes sense.  If anyone has any questions, or suggestions I would be more than welcome to accept them.

Code :
Code: BlitzBasic
  1. ; Simple file save
  2. ;
  3. ; Hope this makes sense :o)
  4. ; Any suggestions for this are welcomed.
  5.  
  6. Graphics 800, 600, 32, 2
  7. SetBuffer BackBuffer()
  8.  
  9. Global FILENAME$                                                                        ; The string that will hold the name of our file.
  10. Global X = 1                                                                            ; A random variable to demonstrate the save.
  11. Global Y = 2                                                                            ; Another random variable to demonstrate the save.
  12.  
  13. Const S = 31, L = 38
  14.  
  15. While Not KeyHit(1)
  16.  
  17.         Cls
  18.        
  19.         Text 0,570,"X: "+x                                                              ; Shows us the value for X
  20.         Text 0,580,"Y: "+y                                                              ; Shows us the value for Y
  21.        
  22.         If KeyHit(S) = True                                                             ; Initiate the save by pressing the 's' key.
  23.                 SAVE()
  24.         EndIf
  25.         If KeyHit(L) = True                                                             ; Initiate the load by pressing the 'l' key.
  26.                 LOAD()
  27.         EndIf
  28.        
  29.        
  30.         Flip
  31.        
  32. Wend
  33. End
  34.  
  35. Function SAVE()
  36.  
  37.         FILENAME$ = (Input("SAVE AS: ")+".file")                ; .file is the extension, change it to whatever you would like to save the file with.
  38.  
  39.         FILEOUT = WriteFile(FILENAME$)                                  ; Open file FILENAME$ to write to.
  40.        
  41.         WriteInt (FILEOUT, X)                                                   ; Write X to the file FILENAME$
  42.         WriteInt (FILEOUT, Y)                                                   ; Write Y to the file FILENAME$
  43.        
  44.         CloseFile (FILEOUT)                                                             ; Since we're done writing to the file we close it.
  45.        
  46.         Cls                                                                                             ; Clear the screen of the text "Save as: ".  Remove CLS to see what i'm talking about if you don't understand.
  47.         Text 0,0,"FILE: "+FILENAME$+" HAS BEEN SAVED"   ; Shows us that the file saved.
  48.         WaitKey()
  49.        
  50. End Function
  51.  
  52. Function LOAD()
  53.  
  54.         FILENAME$ = (Input("LOAD: ")+".file")                   ; Loads the specified file: FILENAME$ with the extension .file
  55.        
  56.         FILEIN = ReadFile(FILENAME$)                                    ; Open the file FILENAME$ to read from.
  57.        
  58.         X = ReadInt(FILEIN)                                                             ; Load the value for X
  59.         Y = ReadInt(FILEIN)                                                             ; Load the value for Y
  60.        
  61.         CloseFile (FILEIN)                                                              ; Since we're done reading from the file we close it.
  62.        
  63.         Cls                                                                                             ; Again, we clear the screen of the previous text.
  64.         Text 0,0,"FILE: "+FILENAME$+" HAS BEEN LOADED"  ; Shows us that the file has been loaded.
  65.         WaitKey()
  66.        
  67.  
  68. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal