1

I've developed a game with in-game currency. When I test the game (currently it's on Alpha and closed internal on Google Play) and trying to buy my coins by pressing button only once, I receive Purchase succeeds several times. As result instead of purchasing 100 coins I get sometimes 200, sometimes 500 coins, sometime 300 etc. In the confirmation email that I receive from Google Play only one transaction happened. Here is the code fro Purchase succeeds event:

public function _customEvent_100gold():Void
 {
  if((_adding100gold == false))
  {
   _adding100gold = true;
   _byinggold = true;
   _secondsbeforeclose = 0;
   Engine.engine.setGameAttribute("gold", ((Engine.engine.getGameAttribute("gold") : Float) + 100));
   trace("adding 100 gold");
   _coinicon.setX((actor.getX() + (((((actor.getWidth()) - getFont(660).font.getTextWidth(("" + (Engine.engine.getGameAttribute("gold") : Float)), getFont(660).letterSpacing)/Engine.SCALE) / 2) + 20) - 45)));
   purchasesUse("100gold");
   purchasesGoogleConsume("100gold");
   playSound(getSound(795));
   saveGame("mySave", function(success:Bool):Void
   {
    runLater(1000 * 0.6, function(timeTask:TimedTask):Void
    {
     _pressedonce = false;
     _adding100gold = false;
    }, actor);
    _coinicon.growTo(145/100, 145/100, 0.3, Easing.elasticOut);
    runLater(1000 * 0.3, function(timeTask:TimedTask):Void
    {
     _secondsbeforeclose = 0;
     _100gold.growTo(100/100, 100/100, 0.3, Easing.elasticOut);
     _coinicon.growTo(100/100, 100/100, 0.6, Easing.elasticOut);
     runLater(1000 * 0.3, function(timeTask:TimedTask):Void
     {
      _byinggold = false;
     }, actor);
    }, actor);
   });
  }
 }

So from my understanding my boolean "adding100gold" should prevent from running this code more than once, only after 0.6 seconds after a successful purchase. From my debug log I can see this code is running several times almost simultaneously. The strange thing is I have other in-app product that's always sending me message "purchase failed" and I also receive it on my test device several times in a row. Which shows as well that it runs failed events also several times instead of just once as it should. So how to fix it?

update: I created a brand new Google account and created a new product ID for my 1000 coins in the game. So when I tested on my device when I pressed the button I bought 1000 coins, when I pressed second time I went through the buying process but received not 1000 but 2000 coins. When I pressed button 3rd time I received 3000 coins. It seems that the problem is not in the code but somewhere between my device and Google Play. Is there anything I can check? Like I've already checked my payment method and Public Key. What else?

Guzzz
  • 63
  • 5
  • I've just found a bizarre feature of my problem. I have 2 products: 100 coins and 1000 coins. When I first pressed to buy 1000 coins it gave me 1000 coins without any problems. I've just tried and bought 8 times 1000 coins and I received 8000 coins in total. But, when I tried to buy 100 coins and received "Purchase failed" popup, and after that I pressed buy 1000 coins I've received 2000 coins instead of 1000. And since then I could buy only 2000 coins at a time. I tried 5 more times and every time I pressed buy 1000 coins I received 2000 coins. – Guzzz Oct 18 '19 at 11:11
  • It's a good idea to learn how to use breakpoints for debugging. That way you can determine the stack trace (calling context) of each `_customEvent_100gold`, which should give you some insight into the problem. Alternatively, you can dump the entire stack trace to the log, instead of just `trace("adding 100 gold")`. [Here](https://www.programiz.com/kotlin-programming/examples/convert-stack-trace-string) is some sample code to help you do that. – greeble31 Oct 18 '19 at 17:17
  • You cannot checkout multiple quantity of an in-app SKUs with Google Play. It has to be a bug in your code. – DrPower Nov 08 '19 at 06:28

0 Answers0