• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Universal Getter + Setter: Workaround for nested accessors

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
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
 
Top