playMaker

Author Topic: Compare (e.g.) Color to Array of Colors  (Read 1516 times)

tyb51

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Compare (e.g.) Color to Array of Colors
« on: April 16, 2015, 07:35:47 PM »
Hi,

I've been struggling in creating a custom action that i need in my project but could be useful for other people.
In essence what I'm trying to do is compare a Variable (here a color) and compare it to a small array of predefined values (again colors here).
(I am going to talk further with the example of color here) If the color is equal to one of the colors in the array it should send the event specified for that color.
As I hove ''null' experience in coding, I have no clue what I am doing. But by looking at some examples I achieved atleast something. The layout of the action is atleast what I want; an option to choose the amount of colors to compare with an event to trigger.

Now my real question is how to actualy make this thing work. I've tried something but I see that it's horribly wrong. Could someone please take a look at what I have and what might be the best way to do this?

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Color)]
[Tooltip("Select a random Color from an array of Colors.")]
public class CompareColorToArray: FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmColor compareColor;
public FsmEvent ifFailure;

[CompoundArray("Colors", "Color", "Event")]
public FsmColor[] colors;
public FsmEvent[] events;




public override void Reset()
{
compareColor = null;
colors = new FsmColor[3];
events = new FsmEvent[] {null,null,null};

}

public override void OnEnter()
{
CompareColor();
Finish();
}

void CompareColor()
{
//here I am stuck .. HELP PLEASE
foreach (Color _color in colors)
{
bool storeResult;
var result = compareColor.Value == _color;

storeResult.Value = result;

//etc etc etc

}


}
}
}

tyb51

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Re: Compare (e.g.) Color to Array of Colors
« Reply #1 on: April 17, 2015, 08:13:51 AM »
I fixed it by doing this (see below); but now I don't know how to implement the failure event? I can't seem to find an example valid to my loop.

Code: [Select]
void CompareColor()
{
if (colors.Length == 0) return;

//var isTrue = true;

for (var i = 0; i < colors.Length; i++)
{
if (compareColor.Value == colors[i].Value)
{
Fsm.Event(events[i]);
break;
}

}