#Extra Parameters in new Array functions

1 messages · Page 1 of 1 (latest)

lethal skiff
#

I've looked at the documentation of Array Functions and from what I can tell the only parameters array_foreach, array_filter, etc allow is two parameters, the element and the index and nothing else. is there are way to use these functions and add extra parameters to them for example if I wanted to filter out elements in an array based on a the players current level, I pass level as the extra parameters (if that makes sense) is that possible or would I have to create a custom function to replicate that?

peak owl
#

Taking the example from the docs as a base

function compare(element, index) {
  return element >= value; // Value is an instance variable
}

// This is where we store our extra parameters
var _value = {
  value: global.player_lvl
} 

lvls = [0, 1, 5, 10, 15, 20, 25, 30, ...];
lvlsReached = array_filter(lvls, method(_value, compare));
#

(kind of a rough example, I haven't properly looked at array_filter() but you get the gist)