Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started by: jeanfabre on January 17, 2013, 02:03:55 AM
-
Hi,
Following a request (http://hutonggames.com/playmakerforum/index.php?topic=2890.0), please find a modulo action ( it's very handy actually)
// (c) Copyright HutongGames, LLC 2010-2014. All rights reserved.
/*--- __ECO__ __ACTION__ ---*/
using UnityEngine;
using System;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Math)]
[Tooltip("Find the modulo between two ints dividend % diviser.")]
public class IntModulo : FsmStateAction
{
public FsmInt dividend;
public FsmInt diviser;
[UIHint(UIHint.Variable)]
public FsmFloat result;
[UIHint(UIHint.Variable)]
public FsmInt resultAsInt;
public bool everyFrame;
public override void Reset()
{
dividend = null;
diviser = null;
result = null;
resultAsInt = null;
everyFrame = false;
}
public override void OnEnter()
{
DoModulo();
if (!everyFrame)
Finish();
}
public override void OnUpdate()
{
DoModulo();
}
void DoModulo()
{
try{
int _mod = dividend.Value % diviser.Value;
result.Value = (float)_mod;
resultAsInt.Value = _mod;
}catch(Exception e)
{
Debug.LogWarning("Int Modulo error: "+e);
}
}
}
}
NOTE: You can find now this action on the Ecosystem (https://hutonggames.fogbugz.com/default.asp?W1181) for you to download directly and easily in your project.
bye,
Jean
-
Thank you for the script!
-
Thanks for the custom action, but shouldn't the result always be an FsmInt, not an FsmFloat?
-
Hi,
I think you are right actually.
http://stackoverflow.com/questions/5383050/how-can-i-calculate-div-and-mod-for-integers
Do you need this action modified?
bye,
Jean
-
Please modify this action so that the result is an int.
Thanks.
-
Hi,
Done, and it's also on the ecosystem.
Bye,
Jean