JS Arrays is a small library that aims to extend native array functions to provide identical functionality to JS arrays.
Some useful examples
// Creates a new array which contains just the names of items
var items = [{
name: "Sword",
type: TYPE.melee
}, {
name: "Bow",
type: TYPE.ranged
}]
var item_names = array_map(items, function(item) {return item.name})
// returns a new array ["Sword", "Bow"]
// Creates a new array with the filtered items
inventory = [{id: 4, amt: 32}, {id: 5, amt: 12}]
potion_items = array_filter(inventory, function(slot) {
// item_get() is a global function used to retrieve items details from a slot
return (item_get(slot).type == TYPE.potion)
})
// returns a new array with items related to a potion
// If at least 1 element satisfies the predicate, return true. Otherwise false.
has_ring = array_some(equipped, function(slot) {
return (item_get(slot).type == TYPE.ring)
})
// returns true if they have a ring equipped. False otherwise.
To understand more about each function's details in this library, please refer to various online sources about JavaScript arrays here and here.
Please refer to the Releases page to download the local package / .yyz file.
Game maker doesn't support closures. So doing something like
var some_var = TYPE.potion;
filtered_items = array_filter(inventory, function(slot) {
return (item_get(slot).type == someVar) // error: "some_var" not set before reading it
})
Will not work. Read this for more details on what a closure is, and how it works.
- @dicksonlaw583 - Feather documentation & misc fixes