playMaker

Author Topic: Int Switch To Object Action [SOLVED]  (Read 1626 times)

LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 226
Int Switch To Object Action [SOLVED]
« 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.

Code: [Select]
// (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.
« Last Edit: July 21, 2017, 12:32:26 PM by LordHorusNL »

Deek

  • Full Member
  • ***
  • Posts: 133
Re: Int Switch To Object Action
« Reply #1 on: July 21, 2017, 12:02:36 PM »
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:
Code: [Select]
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.

LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 226
Re: Int Switch To Object Action
« Reply #2 on: July 21, 2017, 12:31:12 PM »
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.
« Last Edit: July 21, 2017, 12:40:49 PM by LordHorusNL »