iPhone saving form data - how and where?

I'm looking at a social interaction app with some game play. I want to create forms and screens so users/players can create personal profiles they can ultimately share over bluetooth/wifi/3G etc. Where and how to I save the data input in the forms? I've found stuff on the player prefs file, but that seems to relate to web games only. Can someone point in the right direction? Examples? Code snippets?

more ▼

asked Dec 14, 2010 at 09:51 AM

avatar image

4 6 5 8

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

1 answer: sort voted first

Player Prefs aren't just for web games. They are good for storing data that you do not want to lose between game sessions. However, they can only save strings, floats, and integer variables, so if you need booleans, you'd be best to use an integer as a flag.

The only thing that you need to be careful of when using Player Prefs is that you do not try to access a null variable. If you do this, the Unity editor will not pick up on it and the game will seem fine, until you build it to a device and you get a SIGBUS error. The way I would go about doing it to prevent this is have some class that initializes all Player Prefs on the first scene to ensure that they all exist when they are needed. For example:

   PlayerPrefs.SetInt(someVariable, 0);

This will check to see if the Player Prefs exists, and if it doesn't, it will be created. It is basically a safeguard against SIGBUS errors.

So for what you are looking to do, you can simply save the input from your text fields into Player Prefs, and they can be accessed during any game session.

Hope this helps

more ▼

answered Dec 14, 2010 at 02:19 PM

avatar image

A Lee
104 18 16 21

Brilliant. Much appreciated.

Dec 15, 2010 at 08:56 AM Duffdaddy
(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: Dec 14, 2010 at 09:51 AM

Seen: 2279 times

Last Updated: Dec 14, 2010 at 10:54 AM