playMaker

Author Topic: Check condition not working...  (Read 1895 times)

Alatriste

  • Full Member
  • ***
  • Posts: 194
Check condition not working...
« on: January 24, 2019, 08:28:43 AM »
I'm pretty new to make my custom actions. I tried to create a few and it was fine. Now I'm trying to create an action that checks if an event has been completed. I'm getting the error: "Object reference not set to an instance of an object". I was using the "Bool test" action as a template, but I have no clue what I'm doing wrong...

This is what I'm trying to achieve:

Code: [Select]
Checking For Completion
if(Journal.GetAchievement("The Reaper").completed)
{
    // Do something fun!
}
You can use this approach to allow the player to do something only if they've completed a specific achievement beforehand.

And this is my action:

Code: [Select]
using UnityEngine;
using GameGrind;

        namespace HutongGames.PlayMaker.Actions
    {
        [ActionCategory(ActionCategory.Logic)]
        [Tooltip("Sends Events based on the value of a Boolean Variable.")]
        public class CheckAchievementCompletion : FsmStateAction
        {

        [Tooltip("The ID of the achievement to track.")]
        public FsmInt achievementID;

        [Tooltip("Get the current status of the achievement ID.")]
        public FsmBool achievementCompleted;



        [Tooltip("Event to send if the Bool variable is True.")]
            public FsmEvent isTrue;

           [Tooltip("Event to send if the Bool variable is False.")]
            public FsmEvent isFalse;

            [Tooltip("Repeat every frame while the state is active.")]
            public bool everyFrame;



            public override void Reset()
            {
                isTrue = null;
                isFalse = null;
                everyFrame = false;
            }

            public override void OnEnter()
            {

                achievementCompleted.Value = Journal.GetAchievement(achievementID.Value).completed;

                Fsm.Event(achievementCompleted.Value ? isTrue : isFalse);

                if (!everyFrame)
                {
                    Finish();
                }
            }

            public override void OnUpdate()
            {
                achievementCompleted.Value = Journal.GetAchievement(achievementID.Value).completed;

                Fsm.Event(achievementCompleted.Value ? isTrue : isFalse);
            }
        }
    }
« Last Edit: January 24, 2019, 08:31:04 AM by Alatriste »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Check condition not working...
« Reply #1 on: January 25, 2019, 02:27:59 AM »
Hi,

 ok, few things:

- in your logic, you are going to send an event every frame, this is not ideal, what you likely want is to send event when the value changed. so you need to cache the value and only send an event when you detect a change.

then, to make sure your code is working, use first an FsmBool where you store the value, so that you can watch it in the action as it plays, once you know you are getting the right value you can send fire events.

 Bye,

 Jean

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Check condition not working...
« Reply #2 on: January 25, 2019, 02:55:38 AM »
Hi.

As jean said the send event every frame is not ideal indeed.

But that probably did not solve the error.
So i purchased the asset as i am interested to make a set of actions for my Third party asset actions for PlayMaker

You probably have your action in a start state.
So it starts right from the beginning and probably Journal is not loaded properly yet.

When you use a "next frame event" or a "wait" and then do the action it should work.

But i will ask the author if he can add a "isLoaded" or "Initiate completed"

Alatriste

  • Full Member
  • ***
  • Posts: 194
Re: Check condition not working...
« Reply #3 on: January 25, 2019, 04:23:03 AM »
That sounds rather complicated...  :-[

I'll wait for the actions of djaydino to see if I can understand the code to find out the right way to do it.