playMaker

Author Topic: PlayerPrefs Has key action misleading  (Read 3034 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
PlayerPrefs Has key action misleading
« on: January 27, 2012, 02:06:26 AM »
Hi,

 When I wanted to user playerPRefs has key action, it took me a while to figure out that it was required that a variable is set to store the result, yet the variable was not flagged as required.

 so I think either it's not necessary, or else, the interface should throw an error if not set.


Here is a version that will work even if no variable is passed. I use this for just directing the flow, It's quicker than creating, and checking a variable.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("PlayerPrefs")]
[Tooltip("Returns true if key exists in the preferences.")]
public class PlayerPrefsHasKey : FsmStateAction
{
[RequiredField]
public FsmString key;

[UIHint(UIHint.Variable)]
[Title("Store Result")]
public FsmBool variable;

[Tooltip("Event to send if key exists.")]
public FsmEvent trueEvent;

[Tooltip("Event to send if key does not exist.")]
public FsmEvent falseEvent;

public override void Reset()
{
key = "";
}

public override void OnEnter()
{
Finish();

if( !key.IsNone && !key.Value.Equals(""))
{
variable.Value = PlayerPrefs.HasKey(key.Value);
}

Fsm.Event(variable.Value ? trueEvent : falseEvent);
}
}
}


 Bye,

 Jean

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3999
  • Official Playmaker Support
    • LinkedIn
Re: PlayerPrefs Has key action misleading
« Reply #1 on: January 27, 2012, 12:57:09 PM »
Thanks Jean! I've included this bug fix in the next release.