- Home /
Why are my PlayerPrefs not showing correct values?
Following Bergzerg Arcade Hack n' Slash tutorial, converting it to uJS.
There is a function to set the current status values to their minimum (Health, Energy, Mana). While all my Debugging shows the function is working correctly, in the registry the values are not showing as expected.
The variable Health_CurrValue is updating, so why are Energy and Mana CurrValue not, when all is done the same way in a loop. I feel I am missing something obvious but for all my repeating the specific video and debugging, I cannot see the problem.
The function in question :
private function UpdateCurrVitalValues()
{
var i : int = 0;
var allEnumValues : String[] = System.Enum.GetNames( VitalName );
for ( var enumValue : String in allEnumValues )
{
var theClassVital : Vital = _toon.GetVital( i );
Debug.Log( enumValue + " GetCurrValue BEFORE : " + theClassVital.GetCurrValue() );
//theClassVital.SetCurrValue( theClassVital.GetAdjustedBaseValue() );
var theValue : int = theClassVital.GetAdjustedBaseValue();
theClassVital.SetCurrValue( theValue );
Debug.Log( enumValue + " theValue : " + theValue );
Debug.Log( enumValue + " GetAdjustedBaseValue : " + theClassVital.GetAdjustedBaseValue() );
Debug.Log( enumValue + " GetCurrValue AFTER : " + theClassVital.GetCurrValue() );
}
}
My console output and registry :
All the Classes can be found on my last question : http://answers.unity3d.com/questions/377081/finding-the-length-of-an-enum-in-a-different-class.html
Thanks, Jay.
Answer by whydoidoit · Jan 23, 2013 at 09:17 AM
You don't appear to be using the loop iterator for anything apart from debugging! i also remains 0 throughout the entire loop.
Ding Ding Ding, So it was that simple, I'm not incrementing i .... far out, massive facepalm =[
All that debugging the enum value, and not a single debug for i, so annoyed at myself.
Regarding the functionality of that function (groan) :
I don't know how to do getters and setters in uJS, so ins$$anonymous$$d of one method that does both jobs, I have written separate functions, basically :
public function GetBaseValue() : int
{
return _baseValue;
}
public function SetBaseValue( theValue : int )
{
_baseValue = theValue;
}
theClassVital.SetCurrValue( theValue ); // is the line in my question that does the work =]
thanks for saving my sanity again (we're not worthy!). All the Best.