Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: qholmes on August 31, 2011, 10:32:22 AM

Title: Random Int with Increment Value
Post by: qholmes on August 31, 2011, 10: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();
}
}
}
Title: Re: Random Int with Increment Value
Post by: Dev_Sebas on August 31, 2011, 10:44:23 AM
Thanks a again
Bye