IAP: Multiple Non-Consumable (durable) items

tjuven

Member
Hi!
I'm in the process of implementing in-app purchases in my mobile game and I've been following the great tutorial from yoyo here. However the guide doesn't mention how to implement more than one non-consumable item and I'm struggling to figure out how to accomplish this. I haven't found any answers to this anywhere else either so I'm kinda lost.

So for the first part I've done this:
Code:
// Store the product names in variables for easy editing
product_consumable_1 = "wb_coins_x2000";   
product_durable_1 = "wb_remove_ads";
product_durable_2 = "wb_coin_doubler";
var map_create = true;        // // This is to tell us if we need to create the save map
if (file_exists("iap_data.dat")) // Check for the file
{
    // The file exists so load the save map
    global.saveMap = ds_map_secure_load("iap_data.dat");
   
    // Check the map has been loaded correctly
    if (ds_exists(global.saveMap, ds_type_map))
    {
        // Check to see if the durable IAP (Remove ads) has been used
        if (ds_map_exists(global.saveMap, product_durable_1))
        {
            map_create = false; 
            if (ds_map_find_value(global.saveMap, product_durable_1) == false)
            {
                // The durable IAP has not been used, so do something
                // like enable ads, or disable extra content, etc...
                global.show_ads = true;
            }
        }
       
        // Check to see if the durable IAP (Remove ads) has been used
        if (ds_map_exists(global.saveMap, product_durable_2))
        {
            map_create = false; 
            if (ds_map_find_value(global.saveMap, product_durable_2) == false)
            {
                // The durable IAP has not been used, so do something
                // like enable ads, or disable extra content, etc...
                global.coindoubler = false;
            }
        }
    }
}
Creating the map:
Code:
// The save map doesn't exist, so create it and initialise the IAPs to false
if (map_create)
{
    global.saveMap = ds_map_create();
    ds_map_add(global.saveMap, product_durable_1, false);
    ds_map_add(global.saveMap, "remove ads consumed", 0);
    ds_map_add(global.saveMap, product_durable_2, false);
    ds_map_add(global.saveMap, "coin doubler consumed", 0);
    ds_map_secure_save(global.saveMap, "iap_data.dat");
}
But for the last part I've got this
Code:
// setup purchase data & connect to store ///////////////////////////////
var durable_map = ds_map_create();
var productList = ds_list_create();
// Create durable iap (Remove ads / Coin doubler)
ds_map_add(durable_map , "id", product_durable_1);
ds_map_add(durable_map , "title", "Test Durable");
ds_map_add(durable_map , "type", "Durable");
ds_map_add(durable_map , "id", product_durable_2);
ds_map_add(durable_map , "title", "Test Durable");
ds_map_add(durable_map , "type", "Durable");
ds_list_add(productList, durable_map);
// Create consumable IAP (Coins)
var consumable_map = ds_map_create();
ds_map_add(consumable_map, "id", product_consumable_1);
ds_map_add(consumable_map, "title", "Test Consumable");
ds_map_add(consumable_map, "type", "Consumable");
ds_list_add(productList, consumable_map);
// Activate IAP
iap_activate(productList);
// Clean up
ds_map_destroy(durable_map);
ds_map_destroy(consumable_map);
ds_list_destroy(productList);
And I guess I can't do it like that since there can't be two items in the "durable_map" with the same key ("id")? The xcode console tells me that the first non-consumable and the single consumable works and I get all the info regarding those items however.

All help is greatly appreciated, thanks!
 
Top