Creating a save game file

Previous topic - Next topic

ggindlesperger

I am a little stuck on saving data from a game on the iPhone. I really only want to save 3 variable...score, high score, and level. All of them integers. I believe I understand openfile and I am aware of SUB GLB_ON_QUIT to save date on a sudden quit. My problem is I do not know how you create the file in the first place to write too. Is it as simple as creating a file in your working directory for your project, or does it have to be a certain name or place on the iPhone. Any help or code on how to create the file, write to the file, and later read from the file would be greatly appreciated.

Thanks in advance for any help.

Kitty Hello

Write it in the directory you get with PLATFORMINFO$("DOCUMENTS")

Hark0

#2
I use this:

Code (glbasic) Select
SUB GLB_ON_QUIT:

Disco=OPENFILE(1, Fichero_Config$, FALSE)
IF (Disco)
    WRITEBYTE 1,RELOJ_TIEMPO_JUEGO_HRS%
  WRITEBYTE 1,RELOJ_TIEMPO_JUEGO_MIN%
  WRITEBYTE 1,RELOJ_TIEMPO_JUEGO_SEC%
  WRITEWORD 1,CONTADOR_EJECUCIONES%
  WRITEBYTE 1,MUSICA_SISTEMA%
  WRITEBYTE 1,SONIDO_FX_SISTEMA%
  WRITEBYTE 1,PARTIDA_INICIADA%
    CLOSEFILE 1
    ENDIF

ENDSUB


And of course... when the app starts... first of all I use:

Code (glbasic) Select
FUNCTION Carga_Config_Disco:

Disco=OPENFILE(1, Fichero_Config$, TRUE)
IF (Disco)
    READBYTE 1,RELOJ_TIEMPO_JUEGO_HRS
    READBYTE 1,RELOJ_TIEMPO_JUEGO_MIN
    READBYTE 1,RELOJ_TIEMPO_JUEGO_SEC
    READWORD 1,CONTADOR_EJECUCIONES
    READBYTE 1,MUSICA_SISTEMA%
  READBYTE 1,SONIDO_FX_SISTEMA%
  READBYTE 1,PARTIDA_INICIADA%
  CLOSEFILE 1
ENDIF
ENDFUNCTION


Don't forget to declare variable:

Code (glbasic) Select
Fichero_Config$=PLATFORMINFO$("DOCUMENTS")+"/ProyectoLP_Config.dat"

ProyectoLP_Config.dat as the file.

:)
http://litiopixel.blogspot.com
litiopixel.blogspot.com - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

ggindlesperger

Thank you both very much. That should do it for me.