x


Updating variable values.

Hey I am having a problem saving the value of a variable. I have an int variable named healthCounter and after I update the variables value, I call the line of code

PlayerPrefs.SetInt("health", healthCounter);

This should save the current value of healthCounter so that when I run the program the next time when I call the line of code

healthCounter = PlayerPrefs.GetInt("health");

this should update the value of healthCounter to what it was before I closed the program right? Instead though it sets healthCounter as the default value of PlayerPrefs.GetInt which is 0. Does anyone know how to fix this? Any insight would be greatly appreciated.

more ▼

asked Jan 13 '10 at 03:45 AM

user-860 (yahoo) gravatar image

user-860 (yahoo)
31 4 4 7

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

1 answer: sort voted first

As far as I can see, your code should work exactly as you expect, as written. So I'm guessing the problem may lie somewhere else. Perhaps you could post a larger portion of your code, and provide more detail about how you know that your code is being called in the correct order, and that healthCounter really is receiving the value zero.

more ▼

answered Jan 13 '10 at 08:19 AM

duck gravatar image

duck ♦♦
40.9k 92 148 415

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

x5054
x818

asked: Jan 13 '10 at 03:45 AM

Seen: 1213 times

Last Updated: Jan 13 '10 at 03:45 AM