I?m trying to write a highscores file using PUTFILE but it seems that doesn?t work under WIZ.
Reading a post with a related problem under GP2X it recommends to use WRITELINE and sync.
Trying this solution, altought I sync everytime a file has been modified, when I try to read it later it?s not synced untill I restart the game.
So highscores are not been updated till next game restart altought have been synced.
My call for syncing is this: SHELLCMD("sync", TRUE, FALSE, rv)
I?m reading with GETFILE that seems to work fine.
Any workaround?
Have you tried: Opening a null first to reset, then open the one you want?
sorry about the edit..i hit modify by accident, from habit in my own posts lol.
FUNCTION SaveHiscores: amount%
OPENFILE(0,"Hiscores.dat",0)
FOR i=0 TO amount-1
WRITELONG 0,hiscores[i].score
WRITELINE 0,hiscores[i].name$
WRITEWORD 0,hiscores[i].level
NEXT
CLOSEFILE 0
ENDFUNCTION
FUNCTION LoadHiscores: amount%
IF OPENFILE(0,"Hiscores.dat",1)=TRUE
FOR i=0 TO amount-1
READLONG 0,hiscores[i].score
READLINE 0,hiscores[i].name$
READWORD 0,hiscores[i].level
NEXT
CLOSEFILE 0
SORTARRAY hiscores[],0
ELSE
OPENFILE(0,"Hiscores.dat",0)
CLOSEFILE 0
SaveHiscores(amount)
ENDIF
ENDFUNCTION
These Functions work like a charm for me...maybe it?ll be a help for you.
They work on the Wiz, too (I used them in TetWiz).
Of course, you?ll have to declare a typed array hiscores[] (or just replace it with your variables).
Amount% in the functions ist the number of entries in the List (10,5,100,...)
I would check to make sure the file can be written to - assuming it can is a bit dodgy :)
Quote from: MrTAToad on 2009-Jul-05
I would check to make sure the file can be written to - assuming it can is a bit dodgy :)
Usually, You start a Game loading the Hiscore-Table.
The "LoadHicores"-Function checks if a hiscore-File exists, if not it creates one.
Datas can then later be saved to it.
But,yes... A check could also be implented in "SaveHiscores"...
As I asume from your example, maybe the trick part is reading without using GETLINE...
Gonna check it.
Loading/saving to the Wiz works fine - at least my highscore routine for my latest game does anyway. Syncing is not necessary.
GLBasic syncs at the program termination, automatically.
The problem is totally solved.
You just shall never use GETLINE or PUTLINE and all works fine on the Wiz.