Forum rules - please read before posting.

How to use objective state label/description as text tokens

edited February 10 in Technical Q&A

How to use objective state label/description as text tokens?

I see that they have variables that I can use in scripting
AC.KickStarter.inventoryManager.GetObjective (3).states[0]..label

but I'm not sure how to use them in an action list. I don't see them as a text token.

Do I need to write a script to do it or is there a better way to set it up? I'm currently using an action list to scroll through objective states when something happens and I want the objective update to say the state label and description rather than just the name of the objective.

Thanks for any help!

Comments

  • edited February 10

    Welcome to the community, @Avocado.

    First of all: there's a small typo in the "API reference" reported by the Editor - there should only be one stop at the end, i.e.:

    AC.KickStarter.inventoryManager.GetObjective (3).states[0].label
    

    (I'll see this corrected in the next update, thanks.)

    For the issue itself: if an Objective is "selected", then you can display its State Label/Description in a Label menu element - just set its Label type property to Selected Objective, and Objective Text to State Label.

    An Objective becomes selected by clicking on an InventoryBox element set to display Objectives - the default Objectives menu uses this technique.

    Otherwise, scripting can be used to extract the text using the code snippet above, and then display it in a Menu manually. The easiest way to do this is to reserve a Global String variable in the Variables Manager for this, and then set its value to the State label - allowing you to use a Variable token:

    string label = AC.KickStarter.inventoryManager.GetObjective (3).states[0].label;
    AC.GlobalVariables.GetVariable ("MyObjectiveState").TextValue = label;
    

    Be aware, however: the "3" and "0" values in the snippet represent the exact Objective and state. Your code would need to be changed if you wanted to make it dynamic, e.g. the extract the current state of the last-updated Objective.

    I can assist with this if necessary - but I'll need a broader overview of your exact intent. If you can share full details of your situation, I can give more specific advice.

  • Basically I'm trying to make an Objective popup menu that uses state label/description to populate the objective popup menu from the objective popup menu tutorial.

    So I have objectives and when I use an action list to get to the next one when I break a clay pot (or however I change it) I want the description of the last updated objective state to show. I love the objective popup menu and it's exactly what I want but i can't get anything other than the objective name as a parameter.

    I'm not really experienced with this addon yet so I'm trying to get things working the best I can and I might be missing something basic.

    Thanks for your quick response! I left a review last week about how great the support is for this addon.

  • edited February 11

    I used the objective menu as a template and copied it to the objective popup menu. Thanks!

    Wait not that's not working

  • Thanks for the details.

    A bit of scripting is needed to read the ActionList's Objective parameter, and manually extract the current state's Label/Description for use in separate parameters.

    Create two more parameters to the OnObjectiveUpdate ActionList mentioned in the tutorial, set them both to the type "String", and set their names to Label and Description.

    This script, when place in the scene and assigned the ActionList in its Inspector, will update these parameters based on the Objective parameter at the time the ActionList is run:

    using UnityEngine;
    using AC;
    
    public class UpdateObjectivePopUp : MonoBehaviour
    {
    
        public ActionListAsset objectivePopUp;
    
        private void OnEnable () { EventManager.OnBeginActionList += OnBeginActionList; }
        private void OnDisable () { EventManager.OnBeginActionList -= OnBeginActionList; }
    
    
        private void OnBeginActionList (ActionList actionList, ActionListAsset actionListAsset, int startingIndex, bool isSkipping)
        {
            if (actionListAsset != objectivePopUp) return;
    
            int objectiveID = actionList.GetParameter ("Objective").intValue;
            ObjectiveInstance objectiveInstance = KickStarter.runtimeObjectives.GetObjective (objectiveID);
    
            string stateLabel = objectiveInstance.CurrentState.GetLabel ();
            string stateDescription = objectiveInstance.CurrentState.GetDescription ();
    
            actionList.GetParameter ("Label").stringValue = stateLabel;
            actionList.GetParameter ("Description").stringValue = stateDescription;
        }
    
    }
    

    It should then just be a case of updating the Menu: Update content Action to display these parameters instead.

  • I went with subtitles for now but thank you so much! I don't really get why the objectives have all that information if you can't use it for canvases, though. Probably just missing something else about it

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.