playMaker

Author Topic: Random Int with Increment Value  (Read 2687 times)

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
    • View Profile
Random Int with Increment Value
« on: August 31, 2011, 07:32:22 AM »
Incase this helps someone. As per a request.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
// 'inclusiveMax' option added by MaDDoX (@brenoazevedo)
// 'incrementValue' option added by qholmes

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Math)]
[Tooltip("Sets an Integer Variable to a random value between Min/Max.")]
public class RandomIntAdd : FsmStateAction
{
[RequiredField]
public FsmInt min;
[RequiredField]
public FsmInt max;
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmInt storeResult;
        [Tooltip("Should the Max value be included in the possible results?")]
        public bool inclusiveMax;
[Tooltip("Should the value be added to the Variable instead of replace it?")]
        public bool incrementValue;

public override void Reset()
{
min = 0;
max = 100;
storeResult = null;
// make default false to not break old behavior.
    inclusiveMax = false;
incrementValue = false;
}

public override void OnEnter()
{
           
var tmpValue = (inclusiveMax) ?
                Random.Range(min.Value, max.Value + 1) :
                Random.Range(min.Value, max.Value);
   
if (incrementValue)
storeResult.Value = storeResult.Value + tmpValue;
else
storeResult.Value = tmpValue;

            Finish();
}
}
}

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • View Profile
    • Blog
Re: Random Int with Increment Value
« Reply #1 on: August 31, 2011, 07:44:23 AM »
Thanks a again
Bye