Forum rules - please read before posting.

How to run an action through a custom script (and assign the parameters within that same script)?

Alrighty, I feel like I'm asking a lot of questions on here lately, so please forgive me if I'm being annoying with my questions! :)

Anyway, this question isn't any more complicated than what's in the title. Let's say I want to build a custom AI script for an enemy, except the enemy is instantiated into the scene so I can't just have an actionlist handle it, since actionlists only work for objects that are already in the scene. Making sense? I hope so.

So then I would want to write a script that would, for example, (at an appropriate time decided through the script) move the enemy over to a random point. At this point, this enemy would be in the scene, so I would then want to basically call the "Character:Move to Point" action in my script and be able to assign the values. I'm imagining something like this: "ActionCharPathFind(false, charToMove, markerToReach, walk, true, false, false);"  Where you call the "action" and send the variables that it needs to run along with it from another script. Is that, in any way, a possibility? Or is there another way to go about using an action on an instantiated character? (Other than the player)? 

Sorry, hopefully I'll get all these bugs worked out soon and stop asking weird questions on here! But thanks a ton for all the help! And for taking the time to read this!

Comments

  • edited March 2015
    You can make a custom action... but I think you could handle it with an "actionlist asset" (it's an actionlist saved as an asset):

    Take a look at these tutorials:

    http://www.adventurecreator.org/tutorials/referencing-scene-objects-actionlist-assets
    http://www.adventurecreator.org/tutorials/referencing-scene-objects-actionlist-assets-2
    http://www.adventurecreator.org/tutorials/introduction-parameters


  • edited March 2015
    Oh the parameters thing is just what I was looking for! I'm working around with that right now, thanks so much! Follow-up question, since it can't hurt to ask (I'm looking into this myself right now), any idea how to run an actionlist and assign the parameters through script?

    So if I just write a whole separate script from anything else and then when a condition was met, let's say I want to run a custom actionlist from that script, and that actionlist has parameters that need setting. So within my own script, I need to set the parameters for an actionlist and then RUN that actionlist. And it can't be done with global or local variables, I promise. Needs to be done in a custom script..... I'm making the use of AC really hard haha!
  • hehe No problem...

    To execute an actionlist from a script you could just call its interact() method... but I don't know how to pass params as I've never used it.
  • Excellent! I finally figured it out thanks to you! Here's what I ended up doing:

    So you create the action list asset that does whatever you need, set up the parameters for it and all that.

    Then in the script that you want to run/define the parameters for that actionlist, you define an actionlistasset variable:

    public ActionListAsset moveToPointActionList;

    Assign that actionlist in the inspector and whatnot, and then later on in the script to define the parameters and run the actionlist:

    moveToPointActionList.parameters[0].SetValue(charToMove.GetComponent<RememberNPC>().constantID);
    moveToPointActionList.parameters[1].SetValue(characterMarker.GetComponent<RememberTransform>().constantID);
    AdvGame.RunActionListAsset(moveToPointActionList);

    My charToMove and characterMarker variables are predefined variables in the script, but you get the idea. Then it instantiates an actionlist in your scene that's specific to those parameters you set, runs it, then deletes it and you can run it again with totally different parameters! Woot! Thank you so much for the help!
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.