Find Array Element by its Index
Soo every now and then i notice that the only way to get a quick return of an Element of an Array would be the Array function "find" /** (Not counting foreach loops as quick even tho it can be very quick executed) */ which takes the Object as a parameter, but why isn't there a function where it takes the index as parameter and returns the Element of the Array that sits at that position? Most of the time i know what the index of the desired Element is but need the object (reference) itself.
E.g.: Lets say i have a Grid (X=11; Y=11) which holds Tiles (11*11= 121 Tiles Total), in an Array, that can spawn a Room, when a player enters a Unknown Room another Room gets Spawned on every adjacent side of the Entered Room. So through a Colision trigger i get the Room with the corresponding Tile, with this Tile i get the index position of it and can determine where in a grid the other tile index are, so i know where they are but i would have to run a ForEachLoop through an array 3 to 4 times even tho i know their position in the array...
(the 4 index are -> CenterTileIndex + 1, CenterTileIndex - 1, CenterTileIndex - X and CenterTileIndex + X (X stands for the Grid axis size) one index we wouldn't need because the Player came from that direction but we would still need to check if we don't pass the where the Player came from Room through)
That's a unnecessary complexity of O(4n) // (4*121 = 484)
instead of 1 and with a nested loop it could easily be O(n²) // (121² = 14641)
So why again isn't there a the functionality find an Element by its Index? You already have the RemoveAt which removes an Element at an Index by passing it an idenx.. so why not a simple FindAt node?
Have a nice day and keep the amazing work up.
asked Mar 28 '18 at 10:09 PM in Blueprint Scripting
Isn’t this just a “GET” node? It does exactly that, it takes your array and you tell it what index to retrieve and it retrieves whatever element is located at that index.
answered Mar 29 '18 at 12:09 AM
Nebula Games Inc
Follow this question
Once you sign in you will be able to subscribe for any updates here