playMaker

Author Topic: Array List Empty - Every Frame [SOLVED]  (Read 1736 times)

SeanC

  • Junior Playmaker
  • **
  • Posts: 61
Array List Empty - Every Frame [SOLVED]
« on: October 16, 2019, 06:24:33 PM »
Hello!

I am trying to add an "Every Frame" option to the action "Array List Empty" but I am no programmer and its proving a little difficult for me. Is there anyone willing to help me out with this?

Thanks,
Sean
« Last Edit: October 17, 2019, 02:24:21 PM by SeanC »

SeanC

  • Junior Playmaker
  • **
  • Posts: 61
Re: Array List Empty - Every Frame
« Reply #1 on: October 16, 2019, 07:44:30 PM »
Here is what I have, but it just sits in the state and isnt evaluating. I'm not sure what I'm missing.

Code: [Select]
// (c) Jean Fabre, 2011-2013 All rights reserved.
// http://www.fabrejean.net

// INSTRUCTIONS
// Drop a PlayMakerArrayList script onto a GameObject, and define a unique name for reference if several PlayMakerArrayList coexists on that GameObject.
// In this Action interface, link that GameObject in "arrayListObject" and input the reference name if defined.
// Note: You can directly reference that GameObject or store it in an Fsm variable or global Fsm variable

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("ArrayMaker/ArrayList")]
[Tooltip("Check if an ArrayList Proxy component is empty.")]
public class ArrayListIsEmpty2 : ArrayListActions
{

[ActionSection("Set up")]

[RequiredField]
[Tooltip("The gameObject with the PlayMaker ArrayList Proxy component")]
public FsmOwnerDefault gameObject;

[Tooltip("Author defined Reference of the PlayMaker ArrayList Proxy component (necessary if several component coexists on the same GameObject)")]
[UIHint(UIHint.FsmString)]
public FsmString reference;

[ActionSection("Result")]

[Tooltip("Store in a bool wether it is empty or not")]
[UIHint(UIHint.Variable)]
public FsmBool isEmpty;

[Tooltip("Event sent if this arrayList is empty ")]
[UIHint(UIHint.FsmEvent)]
public FsmEvent isEmptyEvent;

[Tooltip("Event sent if this arrayList is not empty")]
[UIHint(UIHint.FsmEvent)]
public FsmEvent isNotEmptyEvent;

        public bool everyFrame;

        public override void Reset()
{
gameObject = null;
reference = null;

isEmpty = null;
isNotEmptyEvent = null;
isEmptyEvent = null;
            everyFrame = false;
        }

public override void OnEnter()
{
PlayMakerArrayListProxy _proxy = GetArrayListProxyPointer(Fsm.GetOwnerDefaultTarget(gameObject),reference.Value,true);

bool _isEmpty = _proxy.arrayList.Count==0;

isEmpty.Value = _isEmpty;

if(_isEmpty){
Fsm.Event(isEmptyEvent);
}else{
Fsm.Event(isNotEmptyEvent);
}

            if (!everyFrame)
                Finish();
        }

        public override void OnUpdate()
        {
            PlayMakerArrayListProxy _proxy = GetArrayListProxyPointer(Fsm.GetOwnerDefaultTarget(gameObject), reference.Value, true);

            bool _isEmpty = _proxy.arrayList.Count == 0;

            isEmpty.Value = _isEmpty;

            if (_isEmpty)
            {
                Fsm.Event(isEmptyEvent);
            }
            else
            {
                Fsm.Event(isNotEmptyEvent);
            }

        }

    }
}

Infamous

  • Playmaker Newbie
  • *
  • Posts: 24
Re: Array List Empty - Every Frame
« Reply #2 on: October 17, 2019, 03:57:54 AM »
Hi,

I’m a beginner so maybe I didn’t understand your question correctly.

However, if I’m trying to make an action every frame but it does not have that option, I would normally make my own loop.

For example:

Array List Empty ————-> Next Frame Event ————> Array List Empty

It’s not every frame, it’s every other frame, but it’s usually fast enough

Hope this helps

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Array List Empty - Every Frame
« Reply #3 on: October 17, 2019, 04:00:13 AM »
Hi.
I actually recently needed this, here is the way i have set it up :

Code: [Select]
// (c) Jean Fabre, 2011-2013 All rights reserved.
// http://www.fabrejean.net

// INSTRUCTIONS
// Drop a PlayMakerArrayList script onto a GameObject, and define a unique name for reference if several PlayMakerArrayList coexists on that GameObject.
// In this Action interface, link that GameObject in "arrayListObject" and input the reference name if defined.
// Note: You can directly reference that GameObject or store it in an Fsm variable or global Fsm variable

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory("ArrayMaker/ArrayList")]
    [Tooltip("Check if an ArrayList Proxy component is empty.")]
    public class ArrayListIsEmpty2 : ArrayListActions
    {

        [ActionSection("Set up")]

        [RequiredField]
        [Tooltip("The gameObject with the PlayMaker ArrayList Proxy component")]
        public FsmOwnerDefault gameObject;

        [Tooltip("Author defined Reference of the PlayMaker ArrayList Proxy component (necessary if several component coexists on the same GameObject)")]
        [UIHint(UIHint.FsmString)]
        public FsmString reference;

        public bool everyFrame;

        [ActionSection("Result")]

        [Tooltip("Store in a bool wether it is empty or not")]
        [UIHint(UIHint.Variable)]
        public FsmBool isEmpty;

        [Tooltip("Event sent if this arrayList is empty ")]
        [UIHint(UIHint.FsmEvent)]
        public FsmEvent isEmptyEvent;

        [Tooltip("Event sent if this arrayList is not empty")]
        [UIHint(UIHint.FsmEvent)]
        public FsmEvent isNotEmptyEvent;

        public override void Reset()
        {
            gameObject = null;
            reference = null;

            isEmpty = null;
            isNotEmptyEvent = null;
            isEmptyEvent = null;
            everyFrame = false;

        }

        public override void OnEnter()
        {
            DoTest();

            if (!everyFrame) Finish();
        }

        public override void OnUpdate()
        {
            DoTest();
        }

        void DoTest()
        {
            isEmpty.Value = (GetArrayListProxyPointer(Fsm.GetOwnerDefaultTarget(gameObject), reference.Value, true).arrayList.Count == 0) ? true : false;

            if (isEmpty.Value)
            {
                Fsm.Event(isEmptyEvent);
            }
            else
            {
                Fsm.Event(isNotEmptyEvent);
            }
        }
    }
}

I also added the action in the attachment below.

I will ask jean if Every frame could be added to the official array maker action.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Array List Empty - Every Frame
« Reply #4 on: October 17, 2019, 04:32:02 AM »
Hi,

 updated and uploaded, you can download it from the ecosystem

Bye,

 Jean

SeanC

  • Junior Playmaker
  • **
  • Posts: 61
Re: Array List Empty - Every Frame
« Reply #5 on: October 17, 2019, 02:23:40 PM »
Works like a charm! Thanks Djay and Jean!