playMaker

Author Topic: Setting the value of FsmVar variable not working?  (Read 2286 times)

Krileon

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Setting the value of FsmVar variable not working?
« on: June 04, 2013, 03: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?

Krileon

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: Setting the value of FsmVar variable not working?
« Reply #1 on: June 04, 2013, 03: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();
}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14684
  • Official Playmaker Support
    • View Profile
Re: Setting the value of FsmVar variable not working?
« Reply #2 on: June 04, 2013, 10:21:54 PM »
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