Forum rules - please read before posting.

Array as a Global Variable?

edited February 2023 in Technical Q&A

Hi everyone,

Hope you are doing well!

I was wondering if it is possible to create an array as a global variable. Specifically, I am trying to create an array of integers.

The purpose on my end is to keep track of dialogue choices that the player clicked when presented with 2-3 options within each "day" of my game. The choices will affect future dialogue options (kind of like in Life is Strange!). The array will contain which option they chose.

I'm also hoping that based on which option the user chooses through the game, the consistently "nice" option (so all 1s) or the consistently "ambiguous" option (so all 3s) as an example, I would hope to give a specific achievement.

Might it be possible to do this natively with AC? Thanks!

Comments

  • edited February 2023

    With custom Remember components, you can seralialize a custom class or varaiables as necessary.

    With Global variables, though: only if you use a String variable, and parse it to/from an array using scripting and a delimiter.

    For example, the choices 1, 3, 2, 3, 3 could be represented in string form as "1;3;2;3;3".

    The Variable: Set Action accepts tokens, so you could update this without scripting - just set the Statement = value to e.g.:

    [var:X];Y
    

    Where X is the ID of the variable, and Y is the value to add.

    Extracting this data would require scripting, though, but it'd just be a case of calling:

    int[] array = AC.GlobalVariables.GetStringValue (X).Split (";"[0]);
    

    Again, where X is the variable's ID.

    This approach may not be so viable if you need to keep track of ordering, though, where the positions of values matter. For that, you'd be better off recording each variable separately - using slashes in labels to separate them by category, e.g: "Choices/A", "Choices/B" etc.

  • Thank you so much! I think I might go for the last option you mentioned, since the ordering does come into play later -- appreciate the heads up! :)

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.