Arrays - n Dimensions

Hi All (:

I would like to build something like this : A multi dimensional array :

NEEDS Hunger / Health / Thirst

  • For hunger, print one of those : I am
    hungry / Do you have anything to eat
    / My stomach hurts
  • For Health, print one of those : I
    feel weak / I have pain
  • For Thirst, print one of those : I
    would enjoy a beer / Find some water
    / I can t breathe

ACTIONS

  • For hunger, offer choice of action :
    Eat pizza / eat rat etc…
  • For Health, offer choice of action :
    sleep / take medecine / ignore
  • For Thirst, offer choice of action :
    drink water / drink urine etc…

VALUES
Each one of offer has a value between 0 and 1 if selected

In other words, I m trying to build a multi dimensional array Data system, but I have no clue how to do that in BP.

This is just an example, I m trying to figure out the logic to build an advanced game system.
Something like [[NEED1[ACTION1[VALUE]],ACTION2[VALUE],ACTION3[VALUE]];NEED2etc]

Thank you for your help guys :slight_smile:

Hi Kinan,

It is pretty simple to treat a 1D array as a 2D array once you always add to and read from the array in the same way.

Say you want a 2D array that is 1x5 (ie, each “row” has 5 columns). Every time you add to the array, you need to add 5 things in the same order, and you need to know the order of those 5. ie maybe 0 is health, 1 is hunger, 2 is thirst etc up until index 4.

So all items in the first row have indicies from [0, 0] to [4, 0]

If we want to look up into the array, we simply need to convert a 2D coordinate back into a 1D index. For example, lets say we are wanting to get the Hunger value of the second item in our array. That 2D value is [1,1].

As a 1D value, 1,1 is converted to 6. We do that by simply multiplying the Y value of the 2D coordinate by the “column” or X width of our array. So far that gives us 5. Then we simply add the X value of the 2D array giving us the value of 6.

Also going from 1D to 2D is pretty easy as well and involves using modulus (remainder). If you like I can dig up some examples.

Sounds fantastic, but I wouldn t mind an example to set this up :slight_smile:

also have you considered an array of structs? structs are similar but great for stuff like this.

You create a struct asset, say “CharacterInfo” and then give it a number of properties with names. Then by making an array of those structs in a blueprint (as variable types), you can easily create new structs. Accessing properties is then a simple matter of index and then breaking the struct to get sub properties.

image showing struct make/break nodes

tks i ll try this :slight_smile: