gnysek
Member
GMS2 added a great functionality, that you can write:
instead
like it was in all previous GM versions.
So, why not extend it further to other structures ?
I think that ds_list, ds_map and ds_grid can be extended this way easily:
would be same as:
would be same as:
and for grid (I choose # character as line separator, you're giving it by rows not by columns):
would be equal to:
This should require no change in runner, as this could be replaced by pre-compile part, so compiler gets same code as without this change.
As proof of concept I made a javascript parser which does what I described above. You can update code to see changes (however this is a simple parser, so putting arrays inside ds_xxx or ommiting ; would break it). I understand that for YYG it will took longer than 30 minutes (which I lost on it), since I've added no stacking for substructures and no code editor parsing, but still this seems not that hard to do.
Check it here: https://jsfiddle.net/gnysek/x3c7eL4c/
Code:
var a = [1,2,3,4];
Code:
var a;
a[0] = 1;
a[1] = 2;
a[2] = 3;
a[3] = 4;
So, why not extend it further to other structures ?
I think that ds_list, ds_map and ds_grid can be extended this way easily:
Code:
map = [? "a" => 1, "b" => 2, "c" => "string",5 => sprite_name];
Code:
map = ds_map_create();
map[? "a" ] = 1;
map[? "b" ] = 2;
map[? "c" ] = "string";
map[? 5 ] = sprite_name;
Code:
list = [| 1, "test", 13, sprite_another];
Code:
list = ds_list_create();
list[| 0] = 1;
list[| 1] = "test";
list[| 2] = 13;
list[| 3] = sprite_another;
Code:
grid = [# 1,2,3,4,5 # 6,7,8,9 # 10];
Code:
grid = ds_grid_create(5, 3);
grid[# 0, 0] = 1;
grid[# 1, 0] = 2;
grid[# 2, 0] = 3;
grid[# 3, 0] = 4;
grid[# 4, 0] = 5 ;
grid[# 0, 1] = 6;
grid[# 1, 1] = 7;
grid[# 2, 1] = 8;
grid[# 3, 1] = 9 ;
grid[# 0, 2] = 10;
This should require no change in runner, as this could be replaced by pre-compile part, so compiler gets same code as without this change.
As proof of concept I made a javascript parser which does what I described above. You can update code to see changes (however this is a simple parser, so putting arrays inside ds_xxx or ommiting ; would break it). I understand that for YYG it will took longer than 30 minutes (which I lost on it), since I've added no stacking for substructures and no code editor parsing, but still this seems not that hard to do.
Check it here: https://jsfiddle.net/gnysek/x3c7eL4c/