[Help] Could someone troubleshoot my random spawning program?

I have this program that uses a table to randomly spawn 7 white squares to the screen, and for some reason it isn't working properly. I have a timer that counts down from 30, and I want my program to spawn 7 white actors as long as the clock is still above 0.

I have attached the program so anyone can view it and help troubleshoot this.

The spawning code is in the actor called timerSpawner.

Thanks in advance!

http://www.mediafire.com/download/2qmwlpbg7o2a573/gridSpawn.zip

Comments

  • ArmellineArmelline Member, PRO Posts: 5,364

    There are two things going wrong here.

    Firstly, you have a loop within a loop. Make the game.GameTime > 0 condition a second condition of the other loop and remove that loop.

    Secondly, you are pulling the co-ordinates from the table where they're stored as text, not integers. Change the two columns to type integer. This shouldn't really matter, but apparently it does.

  • gama3gama3 Member Posts: 29
    edited December 2015

    Ok, I'll give this a shot @Armelline

    Thanks for the input, and good catch on the table value type!

    Edit: Also, are loops within loops not a feature in GameSalad? I'm just recently getting back into using this and I'm not totally aware of all the rules. I do however have experience programming in C, and C++ where loops inside loops are a common thing.

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

    If you click on the Loop behavior (at least in the Mac version), it states in the behavior description that Loop behaviors cannot be placed inside of other Loop behaviors.

    It sure would be useful if we could, though.

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

  • ArmellineArmelline Member, PRO Posts: 5,364
    edited December 2015

    You can effectively have loops within loops. You just have to manually construct one or both of the loops. As @tatiang says, you cannot place a loop behaviour in a loop behaviour, though. Attached is an example project. Since it does work if you do it manually, I wonder why they don't let you do it with two loop behaviours. Perhaps one of the staff can shed some light? I see @GeorgeGS online, maybe we can tempt him in here :P

    In your case, though, you were using one of the loops in a place where either a second condition on the other loop or a rule would serve the same function. So even if you could have a loop in a loop, you didn't want to there.

Sign In or Register to comment.