GLBasic forum

Main forum => GLBasic - en => Topic started by: kaotiklabs on 2009-Jul-04

Title: Problems writing to Wiz
Post by: kaotiklabs on 2009-Jul-04
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?
Title: Re: Problems writing to Wiz
Post by: Hemlos on 2009-Jul-04

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.


Title: Re: Problems writing to Wiz
Post by: hoessi666 on 2009-Jul-05
Code (glbasic) Select
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,...)
Title: Re: Problems writing to Wiz
Post by: MrTAToad on 2009-Jul-05
I would check to make sure the file can be written to - assuming it can is a bit dodgy :)
Title: Re: Problems writing to Wiz
Post by: hoessi666 on 2009-Jul-05
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"...
Title: Re: Problems writing to Wiz
Post by: kaotiklabs on 2009-Jul-05

As I asume from your example, maybe the trick part is reading without using GETLINE...

Gonna check it.


Title: Re: Problems writing to Wiz
Post by: Ian Price on 2009-Jul-05
Loading/saving to the Wiz works fine - at least my highscore routine for my latest game does anyway. Syncing is not necessary.
Title: Re: Problems writing to Wiz
Post by: Kitty Hello on 2009-Jul-06
GLBasic syncs at the program termination, automatically.
Title: Re: Problems writing to Wiz
Post by: kaotiklabs on 2009-Jul-08

The problem is totally solved.
You just shall never use GETLINE or PUTLINE and all works fine on the Wiz.