Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Krileon on June 04, 2013, 06:05:55 PM

Title: Setting the value of FsmVar variable not working?
Post by: Krileon on June 04, 2013, 06:05:55 PM
When using the below it gives me a key/value pair same as using PlayerPrefs, but instead of it being a specific variable it's FsmVar so you can select what variable type you want. Now this works for sending variables to an action, but it doesn't work for setting them.

Code: [Select]
[CompoundArray("Store Variables", "Key", "Value")]
public FsmString[] storeKeys;
[UIHint(UIHint.Variable)]
public FsmVar[] storeVariables;

The chunk of code below is from one of my CoherentUI actions.

Code: [Select]
Dictionary<string, object> setEventCalled( Dictionary<string, Coherent.UI.Binding.Value> options ) {
Dictionary<string, int> index = new Dictionary<string, int>();

if ( storeKeys.Length > 0 ) for ( int i = 0; i < storeKeys.Length; i++ ) {
if ( ( ! storeKeys[i].IsNone ) && ( storeKeys[i].Value != "" ) ) {
index.Add( storeKeys[i].Value, i );
}
}

if ( options.Count > 0 ) foreach ( var option in options ) {
int i;

if ( index.TryGetValue( option.Key, out i ) ) {
if ( option.Value.Type.Equals( Coherent.UI.Binding.ValueType.UInteger ) ) {
storeVariables[i].intValue = (int) (uint) option.Value;
} else if ( option.Value.Type.Equals( Coherent.UI.Binding.ValueType.Integer ) ) {
storeVariables[i].intValue = option.Value;
} else if ( option.Value.Type.Equals( Coherent.UI.Binding.ValueType.Boolean ) ) {
storeVariables[i].boolValue = option.Value;
} else if ( option.Value.Type.Equals( Coherent.UI.Binding.ValueType.String ) ) {
storeVariables[i].stringValue = option.Value;
} else if ( option.Value.Type.Equals( Coherent.UI.Binding.ValueType.Number ) ) {
storeVariables[i].floatValue = option.Value;
}
}
}

return getEventCalled();
}

As there is no FsmVar.Value I used "FsmVar.stringValue" for example. So a below example as follows.

Code: [Select]
FsmVar.stringValue = "Pass";

The above doesn't appear to work. Any idea why? Is it due to using the CompoundArray or do FsmVars just not support setting?
Title: Re: Setting the value of FsmVar variable not working?
Post by: Krileon on June 04, 2013, 06:12:58 PM
Nevermind, was able to solve it by directly changing the FsmVariable value exampled below.

Code: [Select]
Dictionary<string, object> setEventCalled( Dictionary<string, Coherent.UI.Binding.Value> options ) {
Dictionary<string, int> index = new Dictionary<string, int>();

if ( storeKeys.Length > 0 ) for ( int i = 0; i < storeKeys.Length; i++ ) {
if ( ( ! storeKeys[i].IsNone ) && ( storeKeys[i].Value != "" ) ) {
index.Add( storeKeys[i].Value, i );
}
}

if ( options.Count > 0 ) foreach ( var option in options ) {
int i;

if ( index.TryGetValue( option.Key, out i ) ) {
if ( option.Value.Type.Equals( Coherent.UI.Binding.ValueType.UInteger ) ) {
storeVariables[i].intValue = (int) (uint) option.Value;
} else if ( option.Value.Type.Equals( Coherent.UI.Binding.ValueType.Integer ) ) {
storeVariables[i].intValue = option.Value;
} else if ( option.Value.Type.Equals( Coherent.UI.Binding.ValueType.Boolean ) ) {
storeVariables[i].boolValue = option.Value;
} else if ( option.Value.Type.Equals( Coherent.UI.Binding.ValueType.String ) ) {
var newString = this.Fsm.Variables.GetFsmString( option.Key );
newString.Value = option.Value;
//storeVariables[i].stringValue = option.Value;
} else if ( option.Value.Type.Equals( Coherent.UI.Binding.ValueType.Number ) ) {
storeVariables[i].floatValue = option.Value;
}
}
}

return getEventCalled();
}
Title: Re: Setting the value of FsmVar variable not working?
Post by: jeanfabre on June 05, 2013, 01:21:54 AM
Hi,

 FsmVar needs some work on that front indeed.

IF you get ArrayMaker, there is a PlayMakerUtils class, where I have wrappers to work with FsmVar, so that your actions stays clean.

I have attached a package here, of just the utils.


bye,

 JEan