What is a mapped array?

The new value “mapped array” makes no since to me. Please explain it with an example. Thaks for reading! :slightly_smiling_face:

First of all, it’s one of those values that takes an array and evaluates each element, such as Filtered Array or Sorted Array. Mapped Array also outputs a modified version of the original array, just like those two values (and unlike Is True For Any/All).

But instead of removing elements (Filtered Array) or changing the order of elements (Sorted Array), Mapped Array modifies each element, while keeping the same amount of elements and order.

Example 1:

Global.A = Array(1, 2, 3, 8, 44, 23);

// I want to have a new array, which is Global.A but with every element multiplied by 2. Let's use Mapped Array.
Global.B = Mapped Array(Global.A, Current Array Element * 2);

Output (viewed from the Workshop Inspector or something):

Global.A: [1, 2, 3, 8, 44, 23]
Global.B: [2, 4, 6, 16, 88, 46]

Example 2:

Global.A = All Players(All Teams);

// I want an array containing the positions of every player in Global.A.
Global.B = Mapped Array(Global.A, Position Of(Current Array Element));

// In Global.B, the vector at index N will be the position of the player at index N in Global.A.

// These arrays are "parallel," meaning that the value from an index of one array is related in some way to the value from the same index of another array.

// This can be useful when dealing with "custom objects" like a collectable pickup.
// You can store the position of a pickup at an index in one array, and the cooldown of the same pickup at the same index of another array.

Output, assuming that Player1 is at 0, 0, 0 and Player2 is at 1, 2, 5:

Global.A: [Player1, Player2]
Global.B: [(0, 0, 0), (1, 2, 5)]
10 Likes

Thank you! This helps a lot! :+1:

I was confused by the mapped array as well, definitely bookmarking this.

Unfortunately it does work with value calculations only, so actions wont work. There goes my hope to inline iterate over an array :stuck_out_tongue: