BoolPrefs

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Removing all content from page)
m (Reverted edits by Joseph05408 (Talk); changed back to last version by Eric5h5)
Line 1: Line 1:
 +
[[Category: Utility Scripts]]
 +
[[Category: JavaScript]]
 +
Author: Eric Haines (Eric5h5)
 +
==Description==
 +
So you're missing SetBool and GetBool from PlayerPrefs?  Worry not, here they are!
  
 +
== Usage ==
 +
Have this script somewhere in your project.  Call it PlayerPrefsX, and then you can use PlayerPrefsX.GetBool and PlayerPrefsX.SetBool as you would expect.  These use PlayerPrefs.SetInt and GetInt behind the scenes (0 = false, 1 = true), so they're just convenience functions.
 +
 +
== PlayerPrefsX.js ==
 +
<javascript>static function SetBool (name : String, value : boolean) {
 +
PlayerPrefs.SetInt(name, value?1:0);
 +
}
 +
 +
static function GetBool (name : String) : boolean {
 +
return PlayerPrefs.GetInt(name)==1?true:false;
 +
}</javascript>

Revision as of 19:26, 19 October 2009

Author: Eric Haines (Eric5h5)

Description

So you're missing SetBool and GetBool from PlayerPrefs? Worry not, here they are!

Usage

Have this script somewhere in your project. Call it PlayerPrefsX, and then you can use PlayerPrefsX.GetBool and PlayerPrefsX.SetBool as you would expect. These use PlayerPrefs.SetInt and GetInt behind the scenes (0 = false, 1 = true), so they're just convenience functions.

PlayerPrefsX.js

<javascript>static function SetBool (name : String, value : boolean) { PlayerPrefs.SetInt(name, value?1:0); }

static function GetBool (name : String) : boolean { return PlayerPrefs.GetInt(name)==1?true:false; }</javascript>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox