x


Deleting PlayerPref problem

Basically i have a piece of code that captures a players score and is then used later to show the score.

The problem i am having though is the fact that when a player resets the level the player pref is not deleting even though i have a code telling it to do so:

PlayerPrefs.DeleteKey("Player Score"); PlayerPrefs.SetFloat("Player Score", score);

The above script shows that i am deleting the playerpref before allowing the player to store it again however it is now working.

more ▼

asked May 13 '11 at 12:17 AM

Aaron Ratcliffe gravatar image

Aaron Ratcliffe
15 4 4 8

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

2 answers: sort voted first

You're just deleting the key and then immediately writing it again. This will have the same effect as not deleting it at all. If you want the key to be deleted, then don't write it again.

more ▼

answered May 13 '11 at 01:11 AM

Eric5h5 gravatar image

Eric5h5
80.1k 41 132 519

The delete key is there to remove any previous data so that a new float can be stored. The reason behind this is so that when a player restarts a level the score can be overwritten

May 13 '11 at 10:45 AM Aaron Ratcliffe

@Aaron Ratcliffe: you don't need to do that. Just do SetFloat again and the previous value is overwritten.

May 13 '11 at 09:17 PM Eric5h5

oh ok haha, was sure i tired that and it didnt work. Ill give it another go

May 14 '11 at 10:25 PM Aaron Ratcliffe

Just realised why it wasnt working. I was attempting to save the playerpref during an impossible if statment... /facepalm. Thanks for the help people

May 14 '11 at 10:38 PM Aaron Ratcliffe
(comments are locked)
10|3000 characters needed characters left

Make a -1, and then when you up to the server, just have it check if it's <0, if so, then dont do it, if so, then do it.

more ▼

answered May 13 '11 at 12:20 AM

Justin Warner gravatar image

Justin Warner
6.3k 19 27 65

(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:

x115
x16

asked: May 13 '11 at 12:17 AM

Seen: 1300 times

Last Updated: May 13 '11 at 12:17 AM