playMaker

Author Topic: Int Modulo  (Read 3341 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14055
  • Official Playmaker Support
    • View Profile
Int Modulo
« on: January 17, 2013, 12: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, 06:11:38 AM by jeanfabre »

BlacKcuD

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

saxton

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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14055
  • Official Playmaker Support
    • View Profile
Re: Int Modulo
« Reply #3 on: February 11, 2014, 11:48:49 AM »
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
    • View Profile
Re: Int Modulo
« Reply #4 on: July 28, 2014, 09:48:14 AM »
Please modify this action so that the result is an int.
Thanks.

jeanfabre

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

 Done, and it's also on the ecosystem.

 Bye,

 Jean