Code headache with my almost finish game.....

luke2125luke2125 Member, PRO Posts: 225

Hi,

I have a Loop Behavior, that spawns Randomly (10,40) worms, however, after the 3rd time of spawning the worms randomly onto the screen, it goes bezerk, and spawns endlessly, please see below:

When ANY conditions:

Numeric Expression : Table Cell ( gameobjectives_tb,1, 8 ) = 1 True to Spawn Worms
Numeric Expression : Table Cell ( gameobjectives_tb,1, 4 ) = 0 If Worm Count is < = 0

Worm Spawn Loop

Loop WHILE ALL Table Cell ( 1, 4 ) < = random ( 10, 40 )

Change Attribute : game.wormcounterrandom To random ( 1 , 164 )

Change Table : Table game.gameobjectives_tb
Row: 1
Column: 4 Value: TableValueCell ( gameobjectives_tb,1,4)+1

Spawn Worm: Actor: worm1
Direction: 0
Position: tableCellValue( game.boardpositions_tb,1,wormcounterrandom )
Position:tableCellValue ( game.boardpositions_tb,2,wormcounterrandom )

If someone can help, would be really appreciative....Thanks and God Bless....

Sincerely,

Sunday

Comments

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

    It seems like you could simplify this problem to this:

    Loop WHILE ALL Table Cell ( 1, 4 ) < = random ( 10, 40 )

    Change Table : Table game.gameobjectives_tb
    Row: 1
    Column: 4 Value: TableValueCell ( gameobjectives_tb,1,4)+1

    How are you restarting the loop after it finishes?

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

  • luke2125luke2125 Member, PRO Posts: 225

    Hi Tatiang,

    Thanks for the response, well, I restart the loop by below:

    When ALL : tableCellValue(game.gameobjectives_tb, 1, 4 < = 0

    Change Table : game.gameobjectives

    Row : 1
    Column : 8 Value: 1 True to Spawn Worms

    Change Table : game.gameobjectives Reset Worm Counter

    Row : 1
    Column : 4 Value: 0

    The thing is that, after the health bar of my character reaches zero it goes to Game Over Screen, from there I go to Main Menu, then when I press PLAY Button, I have some Reset Variables there, and then it goes bezerk, the code. After like the 3rd time, it starts spawning endless, the worms that is. God Bless...

    Sincerely,

    Sunday

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

    I have some Reset Variables there, and then it goes bezerk, the code.

    Problems like this are really hard to troubleshoot on the forums primarily because there is information you're not posting, probably because it seems unrelated to the problem (but isn't). For example, where and when and how you reset the variables is key.

    I have two suggestions: post the project file (you may want to remove any assets and even actors that aren't related to the issue) or hire someone to help with this.

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

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited March 2016

    that loop condition maybe the issue. I see you resetting the rule but not the loop condition. That condition makes no sense and the random should be picked and stored in a self attribute so you can change it to restart the loop or pick another condition to start stop the loop.

Sign In or Register to comment.