playMaker

Author Topic: Listening and waiting for multiple events  (Read 1758 times)

playsteven

  • Junior Playmaker
  • **
  • Posts: 75
Listening and waiting for multiple events
« on: April 06, 2016, 05:59:51 AM »
Hey there,

I'm having problems with my Restore IAP button, as the Finished Checking event usually fires before all the events which check if the IAP have been purchased. I need to wait for a few seconds before the action finishes.

Say the following type of code ...

Code: [Select]
{
store.purchaseditems += purchaseditems;
store.finishedchecking += finishedchecking;
store.checkpurchases();
}

void purchaseditems ( item )
{
  if ( item == correctitem)
   {
   Fsm.Event (successEvent);
   Finish();
   }
}

void finishedchecking ()
{
   Fsm.Event (failEvent);
   Finish();
}

If I add a wait for 3-4 seconds line before the failEvent in finishedchecking() would purchaseditems() still fire away for each item to check, or would the whole routine pause?

Would I need to put an extra Finish() at the end of purchaseditems (for items which don't make the IF statement TRUE) to allow this to fire again or would that quit the whole action?

This is a rather big issue for me, so I'd be grateful for any advice  :)


Chizzler

  • Junior Playmaker
  • **
  • Posts: 67
Re: Listening and waiting for multiple events
« Reply #1 on: April 06, 2016, 11:03:10 AM »
As far as I know, Wait doesn't pause actions taking place in the state, it just stops it progressing to the FINISHED (or named) transition. So you can continue to do your checks

That said, wouldn't it be better to set up a system where it can't progress till the checks have been completed? you can use bool's to track which checks have been done and only progress when all bool's are true. Without this, there could be issues on slower devices, which take too long to process your checks
« Last Edit: April 06, 2016, 11:06:26 AM by Chizzler »

playsteven

  • Junior Playmaker
  • **
  • Posts: 75
Re: Listening and waiting for multiple events
« Reply #2 on: April 06, 2016, 11:13:33 AM »
Thanks Chizzler,

I'm using Prime31's StoreKit plug-in, and when you do a checkpurchases request it fires for each IAP purchase the user has made, and also fires when it completes.

The problem is you don't know if there is any/or how many purchases there are, and the complete can fire off before the purchases are processed, so it's impossible to check the progress.

I think I may have to do all this in the one action.

Cheers,
Steven