#IF problem

28 messages · Page 1 of 1 (latest)

bright onyx
#

Hi, im trying to make a space shooter game and i have a problem when i clear the lvl. The problem is that when i clear all the enemies of the current lvl it pops a message for me to choose an upgrade but the program keeps generating enemies and when i choose the upgrade there are enemies when it wasnt suposed to.

calculateBulletCollision method diminishes the enemiesToClear variable, so when it is 0 stop changes to true and it shouldnt generate new enemies till i choose the upgrade.

I tried debuging but i cant see the error.

analog pagodaBOT
#

This post has been reserved for your question.

Hey @bright onyx! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

bright onyx
#

if its necessary to see the complete code i got it uploaded on my github

half badger
#

Are you using multithread to generate enemies?

#

You did't really show the key code,show complete code will help

bright onyx
#

thats my github repository

#

i just uploaded a new commit

bright onyx
#

idk if you can see it i think its public

analog pagodaBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

half badger
#

Try to create a breakpoint on this 'if' statement

#

So i see you put too many operation inside this if statement. Operator precedence may work not the way you think what it should be

analog pagodaBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

bright onyx
lyric pine
#

Wouldn't a FOR loop work better here?

bright onyx
#

where? in createEnemy method?

lyric pine
#

Yeah

#

You're doing increments

#

Loops work better for increments

bright onyx
#

instead of the if condition you mean?

lyric pine
#

Yeah

bright onyx
#

anyways the problem i have is that it gets in the previous else if condition when it isnt suposed to

rocky panther
# bright onyx anyways the problem i have is that it gets in the previous else if condition whe...

I guess the problem is that you don't calculate existing enemies on the map. Like, you have, for example, 20 enemies spawned on the map, you kill one and your enemiesToClear becames, for example, 1. So you generate one more enemy, even though you still have 19 on the map.
To solve it you need in your if you should also involve existing enemies on the map, like

if (enemiesToClear > enemiesList.size() && ...) {
  // create new enemy
}```
bright onyx
#

the problem is that mi enemiesList has not an initial value, it increases 1 each time a enemy spawns, and decreases 1 when an enemy is destroyed

analog pagodaBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.