x


iphone PlayerPrefs

hi im making a game for the iphone and i have a problem saving the game when the application is closed. i use a gameObject at the first scene that doesnt destroy on load so it goes through all the scenes. Heres my script i dont know what im doing wrong here!! (im trying with just 1 static var to test it)

"money.moneyT" is the static var that i want to save and retrieve when starting the game again.

function Awake(){

DontDestroyOnLoad(this);

}

function Saving(){

PlayerPrefs.SetInt("money", money.moneyT);

}

function Loading(){

PlayerPrefs.GetInt("money");

}

function Start(){

Loading();

}

function OnApplicationQuit(){

Saving();

}

more ▼

asked Jul 05 '11 at 09:10 PM

feak1 gravatar image

feak1
31 5 5 5

Please format your code! If you don't know how, watch the video on how to use Unity Answers here: http://video.unity3d.com/video/7720450/tutorials-using-unity-answers

Mar 21 at 08:33 AM Benproductions1
(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

I tried using PlayerPrefs before on the iPhone, but nothing would ever save. I found this by PreviewLabs, and haven't had a problem since. Might help you?

more ▼

answered Jul 05 '11 at 10:04 PM

gregmax17 gravatar image

gregmax17
46 6 8 10

thx gregmax17, but i still dont get anything saved, i did all the steps that previewlabs said to make it work for javascript.I came out with this script and i still dont see what im doing wrong!!! i dont get any errors i dont know if its the function i use or the order that the functions process...( i mean saving before loading or things like that) or should i have playerspref set to all the script that my static var are in instead of using a single gameObject to save all the vars i need...

import PreviewLabs.PlayerPrefs;

function Awake(){ DontDestroyOnLoad(this); }

function Saving(){

PreviewLabs.PlayerPrefs.SetInt("money", money.moneyT);

}

function Loading(){

 PreviewLabs.PlayerPrefs.GetInt("money");

}

function Start(){

Loading();

}

function OnApplicationQuit(){

Saving();

}

Jul 06 '11 at 07:06 PM feak1

Don't forget to use PreviewLabs.PlayerPrefs.Flush();

Jul 06 '11 at 07:18 PM gregmax17
(comments are locked)
10|3000 characters needed characters left
function Saving(){

PlayerPrefs.SetInt("money", money.moneyT);

PlayerPrefs.Save();

}
more ▼

answered Nov 14 '12 at 09:01 AM

Van Zeng gravatar image

Van Zeng
55 2

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

OnApplicationQuit on IOS not be called

more ▼

answered Mar 21 at 08:39 AM

madjonr gravatar image

madjonr
1

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

i did and still nothing :( whats is wrong i cant figured it out

more ▼

answered Jul 06 '11 at 07:45 PM

feak1 gravatar image

feak1
31 5 5 5

(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

By RSS:

Answers

Answers and Comments

Topics:

x2000
x438
x296

asked: Jul 05 '11 at 09:10 PM

Seen: 1987 times

Last Updated: Mar 21 at 08:39 AM