playMaker

Author Topic: String Multi Test  (Read 3025 times)

amaranth

  • Full Member
  • ***
  • Posts: 172
String Multi Test
« on: October 05, 2012, 11:41:46 PM »
Compares a bunch of strings all at once. For example:

If (string1 = "hello" && string2 = "world")
{
   do this
}

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Tests if all the given String Variables are are equal to thier String States.")]
public class StringTestMulti : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("This must be the same number used for String States.")]
public FsmString[] stringVariables;

[RequiredField]
[Tooltip("This must be the same number used for String Variables.")]
public FsmString[] stringStates;

public FsmEvent trueEvent;
public FsmEvent falseEvent;

[UIHint(UIHint.Variable)]
public FsmBool storeResult;

public bool everyFrame;

public override void Reset()
{
stringVariables = null;
stringStates = null;
trueEvent = null;
falseEvent = null;
storeResult = null;
everyFrame = false;
}

public override void OnEnter()
{
DoAllTrue();

if (!everyFrame)
Finish();
}

public override void OnUpdate()
{
DoAllTrue();
}

void DoAllTrue()
{
if (stringVariables.Length == 0 || stringStates.Length == 0) return;
if (stringVariables.Length != stringStates.Length) return;

bool allTrue = true;

for (int i = 0; i < stringVariables.Length; i++)
{
if (stringVariables[i].Value != stringStates[i].Value)
{
allTrue = false;
break;
}
}

storeResult.Value = allTrue;

if (allTrue)
Fsm.Event(trueEvent);
else
Fsm.Event (falseEvent);
}
}
}

aLDime

  • Playmaker Newbie
  • *
  • Posts: 24
    • http://aldimegame.com/
Re: String Multi Test
« Reply #1 on: January 29, 2014, 04:11:32 AM »
Big thanks! It helped me in the final calculation of winnings places after the race!