Forum rules - please read before posting.

Newbie Question - Adding custom Action & Variables

edited July 2020 in Technical Q&A

I been playing around with adventure creator but I am a bit lost when it comes to variables and custom actions. I created a global variable from the AC game editor then created a custom action but I'm not sure if I'm doing it correctly. Just as a basic testing scenario I made an action to add 1 to the current money.

From the image, have I done it the right way in terms of using the action template correctly and making variables correctly?
https://imgur.com/N5K6ZzQ

Also how do you add variables for other npcs, the same way? or is there a different option for npcs?

Comments

  • Just wanna add that if I wanted to do the above example with parameters, how can I do that? so that I can just enter whatever value I want to add money.

  • Welcome to the community, @Shadowz.

    The code'll work, but you needn't declare "currentMoney" as a class variable because you're only using it in the one function.

    It's also possible to get a reference to a Variable by name, as well as ID. An equivalent Run() function could be:

    public override float Run ()
    {
        AC.GlobalVariables.GetVariable ("Money").IntegerValue += 1;
        return 0f;
    }
    

    But also: this operation can be done using the Variable: Set Action. Unless this is more of an exercise in learning AC's scripting side, do know that you can increase an Integer variable's value by a set amount using this Action.

    Also how do you add variables for other npcs, the same way? or is there a different option for npcs?

    You can attach a "Variables" component to a GameObject, which will then allow you to create variables as part of that object. They can be set/read using AC's Variables Actions as well - just set the Source field to Component.

  • oh thank you

  • edited July 2020

    Sorry to add another question here, but I thought instead of creating another forum I could just ask here since its relating my previous question.

    I added the variables component to the npc, and now I wanna access or set that variable, how can I do that? All npcs will have different amount of money so how can I retrieve a variable from a specific NPC. How is each NPC identified?

  • You don't need to reference an NPC itself - just the Variables component that's attached to it.

    For example, to update a variable attached to an NPC, create a Variable: Set Action, set the Source to Component, and then assign or drag/drop the Variables component you want to affect. You can then choose which variable in that component you want to update.

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.