FrostyCat
Redemption Seeker
Universal Getter + Setter (GMS 1.4)
Overview
This GML extension adds a functional equivalent of the chained accessor feature on the 2.x roadmap, allowing you to reach into deeply nested arrays and data structures in one line. It also adds the ability to use negative index numbers to count backwards from the end on arrays, lists and grids, similar to Python and Ruby.
Downloads
GitHub: Download | Repository
Examples
Overview
This GML extension adds a functional equivalent of the chained accessor feature on the 2.x roadmap, allowing you to reach into deeply nested arrays and data structures in one line. It also adds the ability to use negative index numbers to count backwards from the end on arrays, lists and grids, similar to Python and Ruby.
Downloads
GitHub: Download | Repository
Examples
Code:
var json = '{ "a": [1, 2, { "b": 3 }]}',
json_data = json_decode(json);
show_message(Get(json_data, "a", 2, "b")); //3
show_message(Get(json_data, "a", -2)); //2
Code:
var nested_array = array_create(3);
nested_array[0] = array_create(2, 1);
nested_array[1] = array_create(2, 4);
nested_array[2] = array_create(2, 9);
Set(nested_array, -1, 1, 16);
show_message(Get(nested_array, 2, 0)); //9
show_message(Get(nested_array, 2, 1)); //16