Trying to learn the scripting side of AC, I've done a simple custom Action that simply just adds 1 Strength:
Code:
[System.Serializable]
public class AddStrength : Action
{
// Declare variables here
public AddStrength()
{
this.isDisplayed = true;
category = ActionCategory.Custom;
title = "Add Strength";
description = "Test for adding Strength";
}
public override float Run ()
{
AC.GlobalVariables.GetVariable("Strength").IntegerValue += 1;
return 0f;
}
public override void Skip ()
{
Run ();
}
#if UNITY_EDITOR
public override void ShowGUI ()
{
// Action-specific Inspector GUI code here
AfterRunningOption ();
}
public override string SetLabel ()
{
// (Optional) Return a string used to describe the specific action's job.
return string.Empty;
}
#endif
}
Now I wanna do the same thing except with parameters, so I can just enter a value within the parameter to determine how much of a strength I want when using the Editor. Looking at the ActionParameter script, there seems to be a lot of code, I'm not sure if all are necessary or only some. So I would appreciate it if anyone could show me how the above code would work with a parameter.
Thank you!
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Isn't this already possible by using the Action type Variable/Set and the method Increase By Value?
Using the editor yeah it is, but I'm trying to understand the scripting side, so that I may learn how to create my own custom actions with its own logic etc.
Are you referring to "ActionList parameters" - which allow you to override Action field values - or are you just looking to set the value within the Action itself?
Simply exposing the value in the Action itself just needs you to store that value as a public variable, display a field for it in the ShowGUI function, and then use it in the IntegerValue setter.
Also, if your Skip and SetLabel functions don't override anything, they can be safely removed:
If you wanted to also be able to override this field with an Integer parameter (see a tutorial on parameters here), then you can do so by creating another integer variable to store that parameter's ID, and use it to override your set value if non-negative:
A tutorial on writing custom Actions that use ActionList parameters can be found here.
Thank you thats what I needed, and yes I was referring to Actionlist parameters