playMaker

Author Topic: Int Modulo  (Read 5818 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Int Modulo
« 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)

Code: [Select]
// (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 for you to download directly and easily in your project.

bye,

 Jean
« Last Edit: July 29, 2014, 09:11:38 AM by jeanfabre »

BlacKcuD

  • Playmaker Newbie
  • *
  • Posts: 1
Re: Int Modulo
« Reply #1 on: December 12, 2013, 01:57:37 PM »
Thank you for the script!
« Last Edit: December 12, 2013, 01:59:37 PM by BlacKcuD »

saxton

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Int Modulo
« Reply #2 on: February 11, 2014, 01:29:44 PM »
Thanks for the custom action, but shouldn't the result always be an FsmInt, not an FsmFloat?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Int Modulo
« Reply #3 on: February 11, 2014, 01:48:49 PM »
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

Khoa1994

  • Playmaker Newbie
  • *
  • Posts: 33
Re: Int Modulo
« Reply #4 on: July 28, 2014, 12:48:14 PM »
Please modify this action so that the result is an int.
Thanks.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Int Modulo
« Reply #5 on: July 29, 2014, 09:16:10 AM »
Hi,

 Done, and it's also on the ecosystem.

 Bye,

 Jean