playMaker

Author Topic: Triggering long lasting Events on Items in Array with tiny delay - How? [SOLVED]  (Read 1566 times)

Neikke

  • Full Member
  • ***
  • Posts: 134
Hi, how do I quickly but consequently trigger long lasting events on multiple items in my Array List? Events that last, let's say, for 3 seconds each - but triggering those Events with tiny 0.1f delay?

For example, I have 20 Coins in my Array list, and I want to trigger a Global Event (move the Coin towards CoinMeter on HUD) which takes 3 seconds for each Coin.

If I will loop through the whole list storing the next item in the Array as GameObject in Result field, having triggered these long lasting event on each of the Coin in my Array - it will just loop through the list super quickly - triggering events that are supposed to last for 3 seconds. But since the looping is happening fast and GameObjects are switching quickly - it just cannot finish those long taking events on each Coin.

Of course, waiting till each Coin is reaching its final destination is not an option as it would take ages to send 20 or more coins to CoinsMeter. So basically what I’m trying to achieve is - nice chain of coins slowly traveling to Coin Meter in the air. How should I implement it? Please help, I'm really cracking my head over this for a few days already! Thanks a lot!
« Last Edit: July 25, 2019, 09:52:30 AM by Neikke »

Thore

  • Sr. Member
  • ****
  • Posts: 480
You need to put a wait action in your loop and tweak the timer.

Neikke

  • Full Member
  • ***
  • Posts: 134
Yep, I tried delaying the loop cycle putting Wait action between loops but it’s not solving it either. Events I’m triggering on coins are lasting for 3 seconds, and if I put a delay of 0.1f  between triggering those long lasting events they will just stop executing once the loop is throwing away current stored Coin and grabs the next one to store it and trigger the next long lasting event on it.

I mean they just don’t have enough time to go through all the needed states inside of this long lasting events. Cos Coins on which those long lasting events are being fired on, are being stored and thrown away much quicker than it’s required to finish those long lasting events.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Hi.
I think you need a different way to do this.

Move the coin Towards coin meter should be handled on a fsm on the coin object, which you can trigger by using 'send event by name' (event does not have to be global)

So on the fsm with the array you would loop thru the coins with a delay (wait .1)
and 'send event by name' to the coin object fsm and the coin can handle moving to the meter and also add the value to the meter when reached.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

 Move the logic on each coin instead, make a loop in a manager without delays, simply store dealys and event lenght in variables, and pass that to each coins. then each coin is responsible to handle it self. this means you process this logic in one go, whcih means your manager is free for more coins should your player progress fast.

Bye,

 Jean

Neikke

  • Full Member
  • ***
  • Posts: 134
Thanks a lot Djaydino and Jeanfabre!

I went with Djaydino's suggestion yesterday and it worked like charm! Thank you so much guys!

What I did is just like you both suggested, moved Moving of Coins towards CoinMeter logic on the Coins and it worked! Djaydino, I also enhanced it with the thing you suggested in my another thread about coins - I used Pooler and a holder which also works great and should be good for performance too! Thank you once again!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Hi.
Np happy to help :)