plyGame Scripting - plyBlox Variables

(Leslie Young) #1

plyBlox Global and Local variables

// supported value types
// Bool - Boolean
// Int - Integer
// Float - Float
// String - String/Text
// Rect - Rectangle (x, y, width, height)
// Color - Color (r, g, b, a)
// Vector2 - Vector2 (x, y)
// Vector3 - Vector3 (x, y z)
// GameObject - Unity GameObject
// UnityObject - Unity Object (like Component, but also others)
// SystemObject - System Object (use for any type not natively supported by variable)

// (Set) plyBlox Global Variables
plyBloxGlobal.Instance.SetVarValue("var_name", some_value);

// (Get) Assuming you saved the value as integer
int i = (int)plyBloxGlobal.Instance.GetVarValue("var_name");

// bit safer if you are not sure if a variable was set of if its value 
// is in another type, like float, that can be converted to int
plyVar v = plyBloxGlobal.Instance.GetVariable("var_name");
int j = 0;
if (v!=null) v.TryGetInt(out j);

// Local Variables are pretty much the same but you need to work through the plyBlox
// object that contains the local variables in question. So simply grab an instance
// of the plyBlox and use similar functions
plyBlox blox = some_game_object.GetComponent<plyBlox>();

// for example, if you wanted to access plyBlox local variables on the player
plyBlox blox = Player.Instance.gameObject.GetComponent<plyBlox>();

plyVar c = blox.GetLocalVariable(string name)
object value = blox.GetLocalVarValue(string name)
blox.SetLocalVarValue(string name, object val)

plyBlox Temp variables

Temporary variables are only available in an Event and is invalid when the Event exit.

There is normally no reason to read the variable in an event script as you are creating the variables to provide data to blocks. Normally you will want to set variables before the event is triggered.

The functions to access temp variables are defined in the plyEvent class

public plyVar GetTempVariable(string name)
public object GetTempVarValue(string name)
public plyVar SetTempVarValue(string name, object val)

The documentation on creating events shows the preferred way of setting the temp variables. Near end of page.

You may use the functions to set it though. The Screens System does this for example to set the temp vars before the event is triggered.

plyEvent ev = GUIManager.Instance.bloxObject.GetEvent(ele.eventName);
ev.SetTempVarValue("param1", ele.eventParam1);
ev.SetTempVarValue("param2", ele.eventParam2);
ev.SetTempVarValue("param3", ele.eventParam3);

Calling C# Scripts from Blox