Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: LordHorusNL on July 20, 2017, 05:41:23 PM
-
Hey guys, i find myself in need of a script to compare an array index to about 10 other ints(options) and if i get a match set an object value to the object value specified on each of the 10 ints and then fire off a finish event.
I've gotten this far by just modifying a Int Switch, but no further :o
Could anybody give me some hints on how to actually set the object value in this script.
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Sends an Event based on the value of an Integer Variable.")]
public class IntSwitchToObject : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmInt intVariable;
public FsmObject objectVariable;
[CompoundArray("Int Switches", "Compare Int", "Set Object")]
public FsmInt[] compareTo;
public FsmObject[] objectValue;
public bool everyFrame;
public override void Reset()
{
intVariable = null;
objectValue = null;
compareTo = new FsmInt[1];
objectVariable = null;
everyFrame = false;
}
public override void OnEnter()
{
DoIntSwitch();
if (!everyFrame)
Finish();
}
public override void OnUpdate()
{
DoIntSwitch();
}
void DoIntSwitch()
{
if (intVariable.IsNone)
return;
for (int i = 0; i < compareTo.Length; i++)
{
if (intVariable.Value == compareTo[i].Value)
{
//objectVariable.Value = objectValue.Value;
return;
}
}
}
}
}
I could offcourse just use a Int Switch with 10 transitions, but that would be a lot of extra states.
-
You actually just have to add [ i ] to objectValue.Value since you set objectVariable to an object of an array by the loop-index.
So the last line before 'return;' should be:
objectVariable.Value = objectValue[i].Value;
It's also prabably better to call this action IntSwitchSetObject, but that's just nitpicking.
There's also the section 'Action Request' that might suit this kind of post more.
-
Well thank you very much Deek! I implemented both your suggestions and the action now works like a charm.
Cheers
And the final script with finish event is attached incase anybody wants it.