Loop Behavior and Timer Behavior Don't Go Together Well?

I made a table that has one column and 400 rows which holds of type REAL. The values represent "after second(s)" spawn this actor.

For example, the first five rows contains the following values: 1, 0.77, 1.89, 0.49, 1.04.
What I am trying to do to have the app spawn an actor after by going through each row, that is spawn after 1 second, and then spawn after 0.77 second, and then spawn after 1.89 second and so on until it reaches the end of the table. I have an attribute that keeps track the row position of the table (it acts as a pointer, purposely for tableCellValue function), the value of this increments by one each time after an actor is spawned.

I used a while loop with the condition that game over Boolean is false. In the "do" body, I added a Timer, where second(s) setting is set to takes in whatever values that we are currently pointing to in the table with the "after" option. In the "do" body of the Timer contains Spawn behavior and the change attribute to increment the row position attribute by one (when the value exceeds the number of rows in the table, set it to 1). I think my algorithm is correct but the Editor is not producing spawn at all after second, and the row position attribute are not increasing by one at all.

Any tips?

Comments

  • AlchimiaStudiosAlchimiaStudios Member Posts: 1,069

    @jackygslX said:
    I made a table that has one column and 400 rows which holds of type REAL. The values represent "after second(s)" spawn this actor.

    For example, the first five rows contains the following values: 1, 0.77, 1.89, 0.49, 1.04.
    What I am trying to do to have the app spawn an actor after by going through each row, that is spawn after 1 second, and then spawn after 0.77 second, and then spawn after 1.89 second and so on until it reaches the end of the table. I have an attribute that keeps track the row position of the table (it acts as a pointer, purposely for tableCellValue function), the value of this increments by one each time after an actor is spawned.

    I used a while loop with the condition that game over Boolean is false. In the "do" body, I added a Timer, where second(s) setting is set to takes in whatever values that we are currently pointing to in the table with the "after" option. In the "do" body of the Timer contains Spawn behavior and the change attribute to increment the row position attribute by one (when the value exceeds the number of rows in the table, set it to 1). I think my algorithm is correct but the Editor is not producing spawn at all after second, and the row position attribute are not increasing by one at all.

    Any tips?

    So the timer is in a loop or is only expecting a value from the table in the expression field for the timer to update?

    I don't think either of those will work anyway.

    Timers will only take the value of the expression in it's state at the start of the first trigger for the timer.

    Loops will not update a timer.

    See restrictions on loops via https://help.gamesalad.com/gamesalad-cookbook/1-getting-started/1-07-behaviors-in-gamesalad/

    Follow us: Twitter - Website

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

    One problem with Timers is that they do not update their expression values during runtime. So if you use an attribute or tableCellValue for the timer duration and then change that value later, the timer will not update to the new value.

    Instead, you need to do something like this:

    Change attribute game.lastSpawnTime to game.Time
    Change attribute game.duration (real) to tableCellValue(table, row, col)

    If attribute game.Time ≥ game.lastSpawnTime + game.duration
    Then
         Spawn Actor
         Change attribute game.duration (real) to tableCellValue(table, row, col)
         Change attribute game.lastSpawnTime to game.Time

    And then increment the row number within the If/Then rule.

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

Sign In or Register to comment.