• 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!

iOS [SOLVED]iap firing multiple times

Pfap

Member
I'm setting up a consumable iap and when I tap to add 36 to my currency it is adding 144. I am currently testing with 1 product.

I made 2 scripts called product_bought() and product_consumed() which I will post below the code used in my async object.


Here the relevant code is:

init_purchases script:
Code:
if os_type == os_ios{

 var purchaseList = ds_list_create();
 var product1 = ds_map_create();

 ds_map_add(product1, "id", "currency_pack_ios");
 ds_list_add(purchaseList, product1);

 iap_activate(purchaseList);

 ds_map_destroy(product1);
 ds_list_destroy(purchaseList);
}

This is the async iap event:
Code:
var type = iap_data[? "type"];


// the load check will run on game start if iap are activated
if type == iap_ev_storeload{ 
 if (iap_data[? "status"] == iap_storeload_ok){
  global.store_available = true;
 }
 else{ 
  global.store_available = false;
 }
}

 
// check for a purchase below. Will fire on game start if the item was not consumed. 
if type == iap_ev_purchase{
 
 var index = iap_data[? "index"];
 
 var temp = ds_map_create();
 iap_purchase_details(index,temp);
 
 // give the user their product
 if ds_map_find_value(temp, "status") == iap_purchased{
  
  var product_id = ds_map_find_value(temp, "product");
  
  // figure out which item is triggering this purchase
  product_bought(product_id);

  purchase_fires += 1;// used to debug
  
 }
 
 ds_map_destroy(temp);
 
}

// consume items
if type == iap_ev_consume{
 
 consumes += 1;// used to debug
 
 
 var product_id = ds_map_find_value(iap_data, "product");
 

 // figure out which item is triggering this purchase
 product_consumed(product_id);
 
}



This is the create event code (the stuff I'm using to debug) for the object that has my iap async event
Code:
purchase_fires = 0;
consumes = 0;
This is the draw event:
Code:
draw_text(10,332,string(purchase_fires));// showed 1
draw_text(10,364,string(consumes));// showed 2

And here are the 2 aforementioned scripts.

product_bought script:
Code:
if os_type == os_ios{
 if product_id == "currency_pack_ios"{
  iap_consume(product_id);
 }
}

product_consumed script:
Code:
if os_type == os_ios{
 if product_id == "currency_pack_ios"{
  global.save_purchases[? "amount"] += 36;
  ds_map_secure_save(global.save_purchases, "iap.json");
 }
}
The above must be firing 4 times.


And finally here is the tap event of the button I am using to get the purchase event to fire:
Code:
iap_acquire("currency_pack_ios", "");


To sum up everything works, except that it gives out 144 instead of 36...
And when drawing my debug variables to the screen (purchase_fires and consumes), the purchase_fires variable is showing 1 as expected, but the consumes variable is showing 2. Which, would make me think thst if anything it should be returning 72 of the currency and not 144.
But, if the iap_ev_purchase is only firing once and the iap_consume() is only firing once why is the map position of global.save_purchases[? "amount"] displaying 144 more than its starting value?

I am testing on an iPhone 6 through testflight if that is needed information.
 

Pfap

Member
I created the object with the iap async event earlier in the game and had it set to persistent and then clicked it into the store room via the editor, so the async event was firing in multiple instances of the iap async object.
Still having other issues though, but I should be able to figure them out... if anyone feels inclined to chime in though feel free.

I had an issue where I tapped back to the main menu, before the store responded with a success message and was not given the currency. I'm going to try making the object persistent again, but making sure there is only ever one instance of it, I may also lock the player in the store_room until the store either comes back with a success or failure message.
 
Top