iap_activate

Enables support for making in app purchases.

Syntax:

iap_activate(product_index);


Argument Description
product_index The index of the ds_list that contains the available purchases.


Returns: N/A


Description

This function enables support for making in-app purchases and prepares GameMaker Studio 2 by supplying the product ds_list that holds a series of ds_maps with the information on each available purchase. This means that you will need to tell GameMaker Studio 2 all the available purchase options by setting them in individual ds_maps (one for each available purchase), which are then stored within a ds_list, which is then "activated" with this function.

The individual purchase maps that are to be stored in the ds_list should have the following format of key-value pairs:

It is worth noting that the only essential keys for any target store setup (per product ID) is the "id".

Activating purchases will also trigger an IAP Event, which creates a special iap_data ds_map of the event type iap_ev_product. This ds_map will have the following additional key:

If you are activating multiple products, then each product will trigger its own IAP Event of the type iap_ev_product where you can then get the product ID. It is worth noting that the Google Play store (for Android) can only process details for products 20 at a time which can lead to quite long load times for applications with a significant number of products.



NOTE: All the key/value pairs that comprise a purchase map are strings!


Example:

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);

The above code will create a ds_list and a ds_map, which is then populated by the information for making a purchase. This map is added to the list and then activated as an available purchase for the game. Finally the ds_list and ds_map are removed to prevent memory leaks as they are no longer needed.


Back: In App Purchases
Next: iap_status
© Copyright YoYo Games Ltd. 2018 All Rights Reserved