hi,
i made a new action to add an int / float to a playerprefs int / float
so not to have to set 3 actions to do this (pp get int, int add, pp set int)
but i am trying to get it to work for multiple variables (Count)
when played i get Nullreference on line 26
// (c) Copyright HutongGames, LLC 2010-2015. All rights reserved.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("PlayerPrefs")]
[Tooltip("Adds a value to a playerprefs int identified by key.")]
public class PlayerPrefsAddInt : FsmStateAction
{
[CompoundArray("Count", "Key", "Variables")]
[Tooltip("Case sensitive key.")]
public FsmString[] keys;
public FsmInt[] add;
private FsmInt[] ppValue;
public override void Reset()
{
keys = new FsmString[1];
ppValue = new FsmInt[1];
add = new FsmInt[1];
}
public override void OnEnter()
{
for(int i = 0; i<keys.Length;i++)
{
if(!keys[i].IsNone || !keys[i].Value.Equals("")) ppValue[i].Value = PlayerPrefs.GetInt(keys[i].Value, ppValue[i].IsNone ? 0 : ppValue[i].Value);
ppValue[i].Value += add[i].Value;
PlayerPrefs.SetInt(keys[i].Value, ppValue[i].IsNone ? 0 : ppValue[i].Value);
}
Finish();
}
}
}
it has to do with the ppValue...
i don't have much experience with arrays and i guess somethings is wrong in that direction...
here is the code from the working "single add int to playerprefs" DO NOT USE THIS in your project as this will be changed when i got this working on multiple values (count)
// (c) Copyright HutongGames, LLC 2010-2015. All rights reserved.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("PlayerPrefs")]
[Tooltip("Adds a value to a playerprefs float identified by key.")]
public class PlayerPrefsAddInt : FsmStateAction
{
[Tooltip("Case sensitive key.")]
public FsmString key;
public FsmInt add;
private FsmInt variables;
public override void Reset()
{
key = "";
variables = new FsmInt();
add = null;
}
public override void OnEnter()
{
if(!key.IsNone || !key.Value.Equals(""))
variables.Value = PlayerPrefs.GetInt(key.Value, variables.IsNone ? 0 : variables.Value);
variables.Value += add.Value;
PlayerPrefs.SetInt(key.Value, variables.IsNone ? 0 : variables.Value);
Finish();
}
}
}