Write to file fails on iPhone

Previous topic - Next topic

bigtunacan

My game is crashing on the iPhone when I try to write to my high score fail.

I have included the error that I'm getting from XCode when I tried to debug this.
Code (glbasic) Select

Status: 0
request: fopen_case("Media/scores.csv", "wb") opens "Media/scores.csv": failed
can't write to file: 
GLB Error: 3
Shut down GLB
glb is shut down
exit


Here is my code to write to the file.  This same code works fine on the PC version of the game with no problems.  Also; I'm able to read from the same file on iPhone, I just can't write to it.
Code (glbasic) Select

OPENFILE(1, "Media/scores.csv", 0)

FOREACH ldr IN ldrarr[]
WRITELINE 1, ldr.name$ + "," + ldr.score%
NEXT

CLOSEFILE 1

spacefractal

Because you cannot write to any files on your program folder and should never use media folder to write anyfiles in that.

You need to use document/app data folder using PLATFORMINFO$ to get the path you can use to save your file...
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

ampos

On my programs I use always this:

Code (glbasic) Select
mpath$=platforminfo$("media")         //media path
dpath$=platforminfo$("documents")  //data (or documents) path
?IFDEF WIN32
dpath$=getcurrentdir$() //so the files are written in the app folder on the PC, and not on the "my documents"
?ENDIF


And every read/write call is

Code (glbasic) Select
loadsprite mpath$+"sprite.png",1
iniopen dpath$+"preferences.ini"

Omadan

Indeed,
just get platforminfo$("DOCUMENTS")

eg: dir$=PLATFORMINFO$("DOCUMENTS")

then you can write to that path.

thanks
Top Arcade Apps - Best game for mobiles and computers

http://www.toparcadeapps.com

Kitty Hello

Please consider "APPDATA" also. The DOCUMENTS is also synced with iTunes and iCloud, where APPDATA is only a local cache.

Crivens

Hmm. So if you sync to iCloud then does that mean any settings or highscores you store here will be shared with other iDevices? If so then on one hand is good for any in-app purchases between devices, on the other it is a pain and APPDATA should be used...

Actually come to think of it this is a very good point. I put all my resized images into DOCUMENTS and not APPDATA. Would then they all be shared between the iDevices? Normally I would use something like ?IFDEF IPHONE but is there another for IPAD (and possible IOS for both as I would want the both option).

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

bigtunacan

Thanks for the help!  It's working now; this was the last bug I needed to work out for my game!  I have just submitted to Chillingo for review... once they reject it I will submit directly to Apple :)