GLBasic forum

Main forum => GLBasic - en => Topic started by: AlienMenace on 2011-May-12

Title: More iOS issues
Post by: AlienMenace on 2011-May-12
Hello,

I have an app running perfectly on my PC but have run into a couple of snafus when running it on my iPhone.
I am using the following code to try and load the previously used settings:

file$=PLATFORMINFO$("DOCUMENTS")+"/test.ini"
file_exist=DOESFILEEXIST(file$)

IF file_exist
   INIOPEN file$
   Ffx_mode=INIGET$("Main", "fx_mode")
   Fselect=INIGET$("Main", "select")
   Fvisible=INIGET$("Main", "visible")
   Fcolor=INIGET$("Main", "color")
   Fmute=INIGET$("Main", "mute")
ENDIF

and here is the code I am using on GLB_ON_QUIT:

   file_exist=DOESFILEEXIST(file$)
   IF file_exist THEN KILLFILE file$
   INIOPEN file$
   INIPUT "Main", "fx_mode", Ffx_mode
   INIPUT "Main", "select",Fselect
   INIPUT "Main", "visible", Fvisible
   INIPUT "Main", "color", Fcolor
   INIPUT "Main", "mute", Fmute
   INIOPEN ""

Works as expected on my PC but broken on the iPhone.

The next problem involves the SOUNDPLAYING command. I want to loop a sound
and since there is no built-in command to do this, I've done it this way:

IF Fmute=0 AND SOUNDPLAYING(sound_channel)=0 THEN sound_channel=PLAYSOUND(703,0.0,1)

This works fine on the PC but on the iphone, the return value of SOUNDPLAYING seems
to always return 0 so it restarts the sound each loop resulting in an annoying humming noise.

This also works as expected on my PC but is broken on the iPhone.
Thanks in advance for the help.
Title: Re: More iOS issues
Post by: Kitty Hello on 2011-May-12
Ha!!! You can't INIOPEN an ini file that does not exist. Stupid, but that's the way.
Title: Re: More iOS issues
Post by: AlienMenace on 2011-May-12
Sorry, I really don't understand your reply...

How exactly are you suppose to create the ini file in the first place then? I based this on the code example from the helpfile which says "Calling INIOPEN on a .ini file that does not exist will cause it to be created."

Any thoughts on why SOUNDPLAYING is not working correctly?
Title: Re: More iOS issues
Post by: MrTAToad on 2011-May-12
You check to see if the INI file is present, and if not, create an empty one (OPENFILE and then CLOSE it straight away).

SOUNDPLAYING does seem like a bug :)
Title: Re: More iOS issues
Post by: AlienMenace on 2011-May-13
I added the following:

   file_exist=DOESFILEEXIST(file$)

   IF file_exist THEN KILLFILE file$

   OPENFILE(1, file$, 0)
   CLOSEFILE 1

Still does not seem to work.
Title: Re: More iOS issues
Post by: quangdx on 2011-May-13
I've been using this to get a sound to loop,
it works for me on PC, Mac and iOS
Code (glbasic) Select

IF SOUNDPLAYING(channel)
ELSE
channel=PLAYSOUND(1,0,1)
ENDIF

Title: Re: More iOS issues
Post by: spicypixel on 2011-May-13
Quote from: quangdx on 2011-May-13
I've been using this to get a sound to loop,
it works for me on PC, Mac and iOS
Code (glbasic) Select

IF SOUNDPLAYING(channel)
ELSE
channel=PLAYSOUND(1,0,1)
ENDIF


You could put...
Code (glbasic) Select
IF NOT SOUNDPLAYING(channel) THEN channel=PLAYSOUND(1,0,1)

little neater unless you put the ENDIF to do something else when it was playing.
Title: Re: More iOS issues
Post by: Kitty Hello on 2011-May-13
@AlienMenace - please post what the debug console shows then.
Title: Re: More iOS issues
Post by: quangdx on 2011-May-13
Quote from: spicypixel on 2011-May-13
Quote from: quangdx on 2011-May-13
I've been using this to get a sound to loop,
it works for me on PC, Mac and iOS
Code (glbasic) Select

IF SOUNDPLAYING(channel)
ELSE
channel=PLAYSOUND(1,0,1)
ENDIF


You could put...
Code (glbasic) Select
IF NOT SOUNDPLAYING(channel) THEN channel=PLAYSOUND(1,0,1)

little neater unless you put the ENDIF to do something else when it was playing.

The code is like that to allow easy expandability later,
but once the program is finished I would go through the code and optimise it,
with things like your suggestion.
Thanks.
Title: Re: More iOS issues
Post by: AlienMenace on 2011-May-13
Thanks for the help guys. I switched everything over to playmusic which did enable me to use AAC files which really cuts down the final size of the package. I do understand that I may not have implemented this the most eloquent way but it still should have worked, right?

The other issue is the bigger issue for me. I have not been able to write an ini file on the iphone. Currently I have this:

global file$
local file_exist

file$=PLATFORMINFO$("DOCUMENTS")+"/test.ini"
file_exist=DOESFILEEXIST(file$)

// CODE AT THE START TO LOAD SAVED VALUES
IF file_exist
   INIOPEN file$
   Ffx_mode=INIGET$("Main", "fx_mode")
   Fselect=INIGET$("Main", "select")
   Fvisible=INIGET$("Main", "visible")
   Fcolor=INIGET$("Main", "color")
   Fmute=INIGET$("Main", "mute")
ENDIF

// CODE I AM USING IN SUB GLB_ON_QUIT TO WRITE A NEW SET OF VALUES
local file_exist

file_exist=DOESFILEEXIST(file$)
IF file_exist THEN KILLFILE file$
OPENFILE(1,file$, FALSE)
CLOSEFILE 1

   INIOPEN file$
   INIPUT "Main", "fx_mode", Ffx_mode
   INIPUT "Main", "select",Fselect
   INIPUT "Main", "visible", Fvisible
   INIPUT "Main", "color", Fcolor
   INIPUT "Main", "mute", Fmute
   INIOPEN ""

Can anybody see what I am doing wrong here?
Thank you!
Title: Re: More iOS issues
Post by: MrTAToad on 2011-May-13
Ah - the GLB_ON_QUIT thing should have given it away.  First of, make sure that AUTOPAUSE TRUE is used.  It would also be a good idea to check to see if GLB_ON_QUIT is actually being called (its quite possible that its not).
Title: Re: More iOS issues
Post by: ampos on 2011-May-13
I have this code on my app and is working:

Code (glbasic) Select
datpat$=PLATFORMINFO$("DOCUMENTS")+"/datos.ini"
INIOPEN datpat$
record=INIGET$("puntos","record")


and in the game_over function:

Code (glbasic) Select
INIPUT "puntos","record",record
KEYWAIT;END


Note that there is no file_exist or anything else, just this sentences related to iniput. Even I noticed I forgot the iniclose...

Check that your record-thing is working OUTSIDE glb_onquit. Once you have it working, move inside glb_on_quit.

If file does not exist, iniget should return "no_data", and iniopen should create the file.
Title: Re: More iOS issues
Post by: ampos on 2011-May-13
Quote from: Kitty Hello on 2011-May-12
Ha!!! You can't INIOPEN an ini file that does not exist. Stupid, but that's the way.

INIOPEN creates the file if it does not exists, or perhaps the thing that create the file is really the iniput thing, but I can promise that I have created a non-existent file just with iniopen+iniput.
Title: Re: More iOS issues
Post by: MrTAToad on 2011-May-13
Unfortunately INIOPEN is a bit inconsistent across the different platforms - it works without the need for an empty file on Windows, Linux etc, but on webOS and Android, you do need the check.
Title: Re: More iOS issues
Post by: ampos on 2011-May-13
My app works the same on WebOS and iOS. In both platform, you dont need the check. "The last angel" app is the example. I use iniopen, iniput and iniwrite to write the language preferences.
Title: Re: More iOS issues
Post by: MrTAToad on 2011-May-13
Odd - I found I did...  It wouldn't write the data unless an empty file was present to start with.
Title: Re: More iOS issues
Post by: AlienMenace on 2011-May-14
Quote from: MrTAToad on 2011-May-13
Ah - the GLB_ON_QUIT thing should have given it away.  First of, make sure that AUTOPAUSE TRUE is used.  It would also be a good idea to check to see if GLB_ON_QUIT is actually being called (its quite possible that its not).

I do have that at the top of my code:

ALLOWESCAPE FALSE
AUTOPAUSE TRUE

Also, I'm pretty sure GLB_ON_QUIT is being called because it writes the file properly on the PC... on the iOS side, who the heck knows. I feel a little like I've been through the wringer with stuff that works properly on the PC side but crashes, doesn't work, etc. on the iOS side. 

Thanks ampos, I'll give that a try next.  :)
Title: Re: More iOS issues
Post by: AlienMenace on 2011-May-14
I tried ampos' suggestion and it still does not work. Here's my current code:

ALLOWESCAPE FALSE
AUTOPAUSE TRUE
GLOBAL file$

file$=PLATFORMINFO$("DOCUMENTS")+"/test.ini"

INIOPEN file$
   Ffx_mode=INIGET$("Main", "fx_mode")
   Fselect=INIGET$("Main", "select")
   Fvisible=INIGET$("Main", "visible")
   Fcolor=INIGET$("Main", "color")
   Fmute=INIGET$("Main", "mute")

WHILE TRUE

DO STUFF

WEND
END

SUB GLB_ON_QUIT:

   INIOPEN file$
   INIPUT "Main", "fx_mode", Ffx_mode
   INIPUT "Main", "select",Fselect
   INIPUT "Main", "visible", Fvisible
   INIPUT "Main", "color", Fcolor
   INIPUT "Main", "mute", Fmute
   INIOPEN ""

ENDSUB

Checked the console in XCode and it indicates that it cannot locate the file when I try to open it at the beginning. I also added:

STDOUT "on quit\n"

to the beginning of the SUB GLB_ON_QUIT: subroutine and it does not display this in the console when I kill the application. Any
ideas why SUB GLB_ON_QUIT: would not be called on program termination?

I also added a STDOUT to GLB_ON_PAUSE: and GLB_ON_RESUME: and they both work fine.

SUB GLB_ON_QUIT: not being called seems to be the problem allright... I am stopping the app from the iOS side whilest in GLB_ON_PAUSE: (minimized) state, does that make any difference?

Thanks.
Title: Re: More iOS issues
Post by: Slydog on 2011-May-16
Is the problem that the app is never entering the GLB_ON_QUIT() routine is because the app is not quitting.
You said it *IS* going in to pause mode, which is different than 'quit'.

Pause appears visually the same as quit, as the iPhone gives the user control back to the iPhone interface, but keeps the app in memory in case you want to restart it.  It frees / unloads the app when it needs more memory.  While 'quit' unloads the app from memory immediately.  That's my understanding.

It should trigger one function *OR* the other.

Just call your save code from your 'pause' code, and reload it in the 'resume' code.

I think Gernot added an option to force an app to never pause, but to always quit.
(Is that what the 'AUTOPAUSE' is for?)

(I've never compiled my game for my iPhone yet, so take this advice with a grain of salt, I just read a few forum posts.)