Forum rules - please read before posting.

PopUp Variable - explain it like i'm five

I've been trying to figure out what PopUp variables are and how they are supposed to be used ideally / correctly.
Googling PopUp Variable isn't very useful - is this term AC specific?

I've been through the manual.
Pop Up Variable
'One of a set of pre-defined labels'
and
Pop Up switch
'Uses the value of a Pop Up Variable to determine which Action is run next. An option for
each possible value the Variable can take will be displayed, allowing for different
subsequent Actions to run.'

Maybe I need to rewatch all the tutorial videos.
Are pop up variables just a way to organise a collection of variables?
Is it just an array of strings? Is it an array of variables?
Can I add and remove values at runtime?

If I add the variables component to a gameObject and then set a PopUp variable it shows all the values (lets say 3 variable, empty, prize, empty) -and then set an initial value...
So would you use this to, for example, have 3 chests and then randomise which chest has a prize and which are empty (by (writing a little code) randomly assigning 1 of the values to each chest?)

Thanks in advance!

Comments

  • oh dear - did not mean to post it in engine dev. will see if I can move it.

  • edited June 2021

    The name "PopUp" comes from its use of Unity's PopUp field to display its values in the Editor. In more traditional programming terms, it's essentially a fixed string array, where the "value" represents an integer index in that array.

    It's best used when a situation can take a discrete set of values/states. If you think of a Boolean has having 2 states (True/False), a PopUp is similar but with X states, where X is the number of strings you give it.

    For example, consider a door that can be open or shut, as well as locked or unlocked. While you could make two separate Bools ("Is Open?" and "Is locked?"), you could combine them into a single PopUp with states "Locked", "Unlocked/Shut", and "Open". If we say that an Open door is unlocked, then any door can only take one of these three states.

    This could also be done with an Integer variable (where you have to note somewhere that 0 = Locked, 1 = Unlocked/Shut etc), but since PopUp variables work with fixed arrays, you have the benefit of:

    • Not being able to set an invalid value
    • Always knowing what each value means

    This convenience also extends to logic processing. By combining the two Bools into one PopUp, you can replace multiple Variable: Check Actions into one Variable: PopUp switch Action to determine the door's exact state in one Action, and react accordingly.

    In the case of your "random loot chest" example, you could use a single PopUp variable with values "Chest A", "Chest B", "Chest C" to determine which chest loot is placed in. However, as it better practice to isolate your game logic where possible, I'd personally recommend giving each chest their own "Has loot?" Boolean variable, and then have a script randomly set one to True and the others False.

  • Thanks Chris!

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.