How to shoot 3 balls using random function and making sure they are not thrown at different times?

bij_sbij_s Member Posts: 23

When a condition applies, I want to throw three balls but I want the balls to be thrown at 3 different random (0,5) times but the trick is to make sure that no two balls get thrown out at the same time. Is this possible?

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited July 2014

    Sure, it's possible. I thought of a way to calculate spawn times (three unique times within five seconds) but the spawn behavior within the loop doesn't seem to be working. Probably because a timer inside of a loop isn't a good idea. But at least this will give you some insight into how to create the timing, which is the hard part.

    Click on the white square and it generates spawn times in a table and displays them. The spawn times are intervals, so an example like...

    2.5 0.2 0.8

    means that the first ball should spawn after 2.5 seconds, the second after 2.7 (2.5+0.2), and the third after 3.5 (2.5+0.2+0.8).

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • bij_sbij_s Member Posts: 23

    Thank you for this. I'll give it a try.

  • bij_sbij_s Member Posts: 23

    Hi Tatiang,
    The question I have regarding your approach is how do we avoid making the first ball to be always thrown first. I don't want a specific ball to be always thrown first. I want the order to be random as well. Is there a way of doing that?

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    @bij_s Make sure to include the '@' symbol when notifying someone with their username.

    @bij_s said:
    The question I have regarding your approach is how do we avoid making the first ball to be always thrown first. I don't want a specific ball to be always thrown first. I want the order to be random as well. Is there a way of doing that?

    Sure. Make a table with three rows. In each row, have a single digit (1, 2, or 3). When you calculate the first timer duration, pick a random row by doing Change Attribute self.randomRow to random(1,3). Then have rules for each possible value, for example:

    If attribute self.randomRow=1 spawn [actor 1] If attribute self.randomRow=2 spawn [actor 2] If attribute self.randomRow=3 spawn [actor 3] Remove Row [tableName] [row:self.randomRow]

    If you're going to repeatedly fire three balls, you may want to first copy the table to a backup table and then copy the backup back once you've used all three rows.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.