Forum rules - please read before posting.

Check state for currently selected objective?

Hi, I'm back again still trying to get my objective menu to work. Currently, my objective screen is like an achievement collection where every objectives are displayed at a specific location in the menu but they are all initially grayed out and locked. I want to be able to click on only the unlocked objective to show its description, while nothing happens when I click on the locked objective. Currently AC allows me to autoselect an objective when I click on its icon, but there's only one action list to call when clicked, and the check objective state action mandates me to select a specific objective instead of what I clicked on.

Now I could technically make a separate menu element and action list for every single objective I have on display...but it's very tedious because I have a lot of objectives. Is there a way to check for states of currently selected objective so I wouldn't need to pick a specific one?

Comments

  • If you need more control over the exact behaviour when clicking your objectives, it's best to rely on some (simple) custom scripting.

    The easiest way to do this is to hook into AC's OnMenuElementClick custom event, which is called whenever the user clicks on a Menu, check that they clicked on your list of Objectives, extract which Objective was clicked, and then react accordingly.

    The example script below (ObjectiveClick.cs) would handle the first two of these three steps:

    using UnityEngine;
    using AC;
    
    public class ObjectiveClick : MonoBehaviour
    {
    
        public string menuName = "Objectives";
        public string elementName = "ObjectivesList";
    
        private void OnEnable () { EventManager.OnMenuElementClick += OnMenuElementClick; }
        private void OnDisable () { EventManager.OnMenuElementClick += OnMenuElementClick; }
    
        private void OnMenuElementClick (Menu menu, MenuElement element, int slot, int buttonPressed)
        {
            if (menu.title == menuName && element.title == elementName)
            {
                MenuInventoryBox inventoryBox = element as MenuInventoryBox;
                var objectiveInstance = inventoryBox.GetObjective (slot);
                //
                Debug.Log ("Click objective " + objectiveInstance.Objective.Title);
            }
        }
    
    }
    

    Add it to the scene for now (we can see about automating this later), amend its Inspector and see if the Console reports the correct Objective when clicked.

    The next step would be to establish the logic of what happens next - this could just be to run an ActionList with a pre-set parameter value. If you can give details on what the logic should be, I can see about amending the script further.

  • I stuck the script into the scene and can confirm it's working in that the console is reporting the correct objective when I click on one.

    The next step is to ideally run a check on the selected objective to see if it's inactive ( I'm using the failed state type for this ) or active. If it's inactive, nothing happens (or I guess it should turn off the selected description and texture elements). If it's active, then it should run a series of actions to turn on the selected description and texture elements, similar to what the current action list ShowSelectedObjective is doing.

  • OK. Here's an updated script that runs a given ActionList if the clicked Objective isn't failed:

    using UnityEngine;
    using AC;
    
    public class ObjectiveClick : MonoBehaviour
    {
    
        public string menuName = "Objectives";
        public string elementName = "ObjectivesList";
        public ActionListAsset actionListToRun;
    
        private void OnEnable () { EventManager.OnMenuElementClick += OnMenuElementClick; }
        private void OnDisable () { EventManager.OnMenuElementClick -= OnMenuElementClick; }
    
        private void OnMenuElementClick (Menu menu, MenuElement element, int slot, int buttonPressed)
        {
            if (menu.title == menuName && element.title == elementName)
            {
                MenuInventoryBox inventoryBox = element as MenuInventoryBox;
                var objectiveInstance = inventoryBox.GetObjective (slot);
    
                if (objectiveInstance.CurrentState.stateType != ObjectiveStateType.Fail)
                {
                    KickStarter.runtimeObjectives.SelectObjective (objectiveInstance.ObjectiveID);
                    actionListToRun.Interact ();
                }
            }
        }
    
    }
    
  • Got it to work, thank you!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.