Skip to content
Dickson Law edited this page Sep 8, 2017 · 2 revisions

Welcome to the GMSugar wiki!

The idea behind GMSugar

In GML, initializing arrays, data structures and dynamic resources is a repetitive, verbose chore. First there is the initializing call, followed by a number of repeated setting calls. Not only is the repetition time-consuming to copy-and-paste, it also distracts from the actual structure of the data and adds the potential for developer error. The code generating the data looks nothing like what a developer would imagine or plan on paper. GMSugar aims to hide the repetition in scripts by borrowing the appearance of the constructor pattern from object-oriented programming, while arranging the arguments in a way that can visually convey the data generated this way.

For example, consider the IAP list from the example for iap_activate() in the GMS 1.x Manual:

var purchaseList, purchase1;
purchaseList = ds_list_create();
purchase1 = ds_map_create();
ds_map_add(purchase1, "id", "LevelPack");
ds_map_add(purchase1, "title", "ExtraLevels1");
ds_map_add(purchase1, "description", "Level Pack 1 for Catch The Clown");
ds_map_add(purchase1, "price", "$1.00");
ds_list_add(purchaseList, purchase1);
iap_activate(purchaseList);
ds_map_destroy(purchase1);
ds_list_destroy(purchaseList);

Notice that ds_map_add(purchase1, is repeated 4 times, and then it needs to be added to the purchase list later separately. GMSugar rolls the repetitive work into scripts so that you can focus on the structure and the data:

var purchaseList = IapList(
  IapProduct("LevelPack", "ExtraLevels1", "Level Pack 1 for Catch The Clown", "$1.00")
);
iap_activate(purchaseList);
ds_list_destroy(purchaseList);

Reference

GMSugar has a growing set of constructors that help you quickly build arrays, data structures and dynamic resources. You can see a complete listing here. If you have an idea for a new constructor or new ways to use a constructor, please feel free open an issue and/or make a pull request.

Clone this wiki locally