How to get number of elements inside of an array?

Hi, I’m making an inventory system and I’ve got a counter with the total slots of the inventory (capacity), now I want to show how much space has been used up. I store the items in the inventory in an array. How do I get the number of elements inside of an array and convert it to text form?

Thanks! :slight_smile:

that didn’t work. already tried it.

it literally just gets the length of the array, nothing else unless I’m using it wrong.

@Dr Caligineus may I also add how unhelpful that rude comment of yours is, and it wasn’t even correct anyway. learn some manners.

Ok, so you want to get the number of elements in the array and then put it in some text to present it to the user, right?

The “Format Text” node sounds perfect for this job (it’s pretty cool). Just right-click in your graph, and then search and select “Format Text”. Then, in the “Format” input of the new node, enter in “Array has {NumElements} elements.” Now here’s the cool part: A new input pin appears on the node called “NumElements.” It’s a wildcard pin, which means you can pump in pretty much any type of value into it and it will work. So, **just wire up the output of the “Array Length” node to the new “NumElements” pin, and it’s done.

End result: If you have 2 elements in the array, it will output “Array has 2 elements”

Hope this helps!

1 Like

The length is the number of elements. My answer is correct and nothing about it is unreasonable. It certainly wasn’t rude - I simply stated facts. I don’t know what your problem is. This is incredibly basic stuff and there was nothing stopping you looking it up yourself.

Array Nodes

1 Like

You can use node “Last index” it will show you last number of an array

1 Like