Before updating to Windows 10 you may need to return your Pro license. More information here

How to script a Save/Load option on IPhone?

Hi! I was doing some research, but I couldn`t find a simple way for recording some information in IPhone. I want do know how save simple data, like de PlayerPrefs, but without loosing them after the program is closed. I want basically save the options of the player and also the local scoreboard of the game. I would really appreciate any help, thx!

-------- EDITED ---------

Like my friend there told me, PlayerPrefs should me saving the variables even when the game is turned off. So now my problem becomes the follow: " Why am I loosing de PlayerPrefs just when my game is closed "? This is where a think the problem is:

function Start(){
    if ( !PlayerPrefs.HasKey("level") ){
        PlayerPrefs.SetInt("level", 2);
        PlayerPrefs.SetInt("sound", 1);
        PlayerPrefs.SetInt("music", 1);
        PlayerPrefs.SetInt("skin", 1);
    iPhoneSettings.screenOrientation = iPhoneScreenOrientation.Landscape;

This is the code executed in my menu screen. I check if the level have already been set, if not ( meaning that this is the first time that the game is running ) I put the values of the PlayerPrefs to the default ones. I'm doing it right? Just remember that if a go to the menu screen during the game, the PlayPrefs continue normal. But if I quit, they come back to the default ones...

more ▼

asked Oct 10, 2010 at 01:20 PM

avatar image

28 7 6 10

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

The data stored usingPlayerprefs should not be lost after the program is closed, so it's ideal for your needs.

more ▼

answered Oct 10, 2010 at 01:30 PM

avatar image

duck ♦♦
51.6k 148 420 546

No, you are wrong. The PlayerPrefs are lost after closing the game. Maybe you are getting confused because when you pause the application, you don't lose the PlayerPrefs, but you can see under the applications that are still running ( double press the IPhone button ) that the game is still there. You can quit the game by holding the finger on the applicantions that are running and them pressing the red button, or turning off the IPhone.

Oct 10, 2010 at 02:41 PM Riliali

Actually, its right. Something must be wrong with your implementation. In my game, closing out of the unity app as you describe and forcing a complete restart does keep the player prefs that I've saved.

Oct 11, 2010 at 12:53 AM leith

Yes man, you are absolutely right! Sorry if I was rude. But my problem persists... Thanks for the help anyway!

Oct 11, 2010 at 01:14 AM Riliali

Maybe you could edit your question to include the code you're using to save your data, so we could see if there are any problems with it.

Oct 11, 2010 at 06:39 AM duck ♦♦

Oh, you did. The code looks okay. Now post the code where you read the values back out!

Oct 11, 2010 at 06:41 AM duck ♦♦
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Oct 10, 2010 at 01:20 PM

Seen: 3281 times

Last Updated: Jul 30, 2013 at 07:24 PM