Playerprefs run differently?

Hi everyone

I am having trouble saving my game on iphone. I have managed to achieve this on Unity but not unity iphone. Everything about the code I have is the same apart from the buttons, which have gone from click to touch. I have tested the buttons and they work fine with other code. My only thoughts are that Playerprefs run differently on the iphone, is this true?

Sunnee

they run differently on every platform.

on the iphone they are done through NSUserDefaults from the iPhone os.

as such they are permanentely in RAM and are size restricted (like they are on the webplayer too or used to up to 2.5 at least)

concerning the size-restrictions: do you know the size-limit? how high is it and how can i measure it?

thanks!
greets, thomas

no idea how high it is but I know that once you cross the border it will crash the app on a regular base …
found that out the hard way in a pure objc application.

its intend is to be used for preferences and alike.
for savegames you should consider using System.IO (file stuff) and the Cache folder of your iphone application

Hi, thanks for the reply. I am still unsure what to do about the script. I have set a var LevelNum to each level and have set it to the Playerprefs when a button is pressed.

I then use this code to get back to the level. I get no errors but nothing seems to work. This method is the one that works on Unity.

var holder2 : int = PlayerPrefs.GetInt("levelNum", -1);

any help would be appreciated.

Sunnee

I have some experience with PlayerPrefs, from the outset it looks like you are getting the “name” then trying to assign a number.

Maybe do:

var holder2 : int = PlayerPrefs.GetInt("levelNum");

to get the value of “levelNum”.

If you want to take away from “levelNum”, you could try:

var holder2 : int = PlayerPrefs.GetInt("levelNum") -1;

the -1 in the function there is so you know when the key was not present, that code is technically correct.

What is technically only half as correct at least at the time is that OS 4 or 4.0.1 somewhere seems to have messed something below the surface and as a consequence it seems like the prefs don’t survive the end of application. Thats at least what threads here implied.

If you have a simple sample showing it, make sure to report it through the bug reporter

hmmmmm does this mean I would need to avoid Playerpref to save on the iphone. This code works fine on Unity (PC Version). Would you recommend another way of saving to an iphone? I just wanted a simple save/ continue feature. :slight_smile:

Sunnee

Not necessarily, although it has been temperamental. How do the editor and .app communicate to each other? Is there a separate .plist file for the editor? When I’ve had problems with PlayerPrefs it seems like theres no definite way to see if the iPhone/iPod is in charge of the .plist data. Maybe this is where it goes a bit wrong. I’ve been able to build to iphone, and the plist data is still there from previous plays.

They don’t communicate.
The editor has nothing to do with how it runs on the device at all.

On the desktop its stored in one way.
On the device Unity relies on the NSUserDefaults system to store the keys

right, i see my problem now! :frowning: thanks for your help!