Forum rules - please read before posting.

Setting ActionList Parameters in Custom Action Script

Hello!

Been working happily and quietly for awhile, and managing to get so much done with the standard actions.

One thing I haven't been able to do is anything beyond a very simple calculation, so I'm working on a custom action to handle it. The end result as adding a variable number of items to the inventory based on the player's skill values.

The below seems to work, but I'm having to go a bit out of the way by:
1. Running calculations using parameters values
2. Writing the result to a global variable
3. Separate standard action to convert the global back into a parameter
4. Separate standard action to assign a number of inventory items (cannot assigned based on the global)

I could get more enterprising and try to assign inventory items directly, and maybe I'll go that way in the end, but for now I'd just like to know how to assign a value to a parameter directly. I see a SetParameterData function in the scripting guide, but haven't been able to make much progress on it and haven't found an example to follow.

Can anyone point to a good example?

Thank you!

Note: only relevant portions of script below:

        public int skillValueParameterID = -1;
        public int toolUseValueParameterID = -1;
        public float skillValue; //pulled from a parameter
        public int toolUseValue; //pulled from a parameter
        public int itemAmountToCreate; //should correspond to a final calculated parameter

        public override void AssignValues(List<ActionParameter> parameters)
        {
            Debug.Log("Calculate Forage: AssignValues...");

            skillValue = AssignFloat(parameters, skillValueParameterID, skillValue);
            toolUseValue = AssignInteger(parameters, toolUseValueParameterID, toolUseValue);
        }

        override public float Run()
        {
            Debug.Log("Item Amount To Create = " + itemAmountToCreate + " (Tool Use: " + toolUseValue + " & " + "Skill Value: " + skillValue + ")");

            itemAmountToCreate = (int)Math.Round(toolUseValue + (toolUseValue * (skillValue * .01)), 0, MidpointRounding.AwayFromZero);
            AC.GlobalVariables.GetVariable("tempInt1").IntegerValue += itemAmountToCreate; //should write to a parameter
            return 0f;
        }

Comments

  • You're setting the skillValue and toolUseValue parameters correctly in the AssignValues function - the other step is to expose the parameterID values in the Action's UI so that the user can optionally set them.

    ParameterID values are just integers, so you can use a regular IntField to expose them. However, AC provides a ChooseParameterGUI function that allows for a neater drop-down with parameter label values, filtered by type.

    A negative ID value equates to it being ignored, so checking for this can then be used to show the non-parameterised field equivalent:

    public override void ShowGUI (List<ActionParameter> parameters)
    {
        skillValueParameterID = ChooseParameterGUI ("Skill value:", parameters, skillValueParameterID, ParameterType.Float);
        if (skillValueParameterID < 0)
        {
            skillValue = EditorGUILayout.FloatField ("Skill value:", skillValue);
        }
    
        // Rest of Action UI code..
    }
    

    A tutorial on this topic can be found here.

  • Thank you, Chris!

    I actually did have that part worked out, and I have exposed both skillValue and toolUsevalue. I just omitted that portion of the code above. The parameter assignment works well, and my action actually does work as-is.

    However, I'm looking to do is write itemAmountToCreate to a parameter on the ActionList internally rather than to a global variable. I have so many global variables that they're a challenge to keep coordinated and select, and my ActionLists are pretty bloated changing parameters into variables, calculating, and turning them back into parameters.

    So I'm looking for the parameter equivalent of:

    AC.GlobalVariables.GetVariable("tempInt1").IntegerValue = itemAmountToCreate;

    ...assuming there is one.

    Probably there's not a direct way to reference the existing ActionList. It's easier with globals, since they're really just in one place. So I assume I'd need to reference an ActionList separately. Which would then mean I'd probably need to allow it as an assignable parameter as well.

    I can start to cobble that together, but just don't see how exactly to write to the parameter in the end.

  • The Reset function can be added to a custom Action, and it passes the ActionList that contains it as a parameter. You could conceivably use this to extract the relevant parameter, i.e.:

    ActionParameter myParameter;
    public override void Reset(ActionList actionList)
    {
        myParameter = actionList.GetParameter ("MyParameter");
        base.Reset(actionList);
    }
    

    This parameter's value could then be updated with:

    myParameter.SetValue (itemAmountToCreate);
    
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.