I have an if/else if statement that doesn't work only until I change it
to an if/else statement. The problem is on line 31 where h should
increment 1 and it should because the previous if statement makes it so the
conditional will open up line 30. Here is the main issue. I need h to increment
so when I press space again a second fireball will fire off. And the weird part
is the second bullet will fire off BUT only after the first bullet crosses
the screen the FIRST time. After that, the 2nd bullet shoots??? When I tested
the program I found that h stays equal to 0 until the first bullet crosses the
screen. Can anybody see why. Thanks for any explanation. Again, this code does
work fine when I just make line 28 an else statement. I just need to understand
what is going on.
if(keystates[SDLK_SPACE])///If space is pressed
if((i==0&&h==0) || (i==0 && h==101))
i++;///increments i to 1 to record static jump with precise y-axis value
if(i==1 && h!=102)
//having i = to 2 in this conditional might pose a problem if I make this program a sidescroller
if(h==101 && i==2)
/**HERE"S THE CONFUSION! When I simply put this as an else statement, the first statement in this function [h++] registers**/
elseif(i==2 || h==102)///program works like a charm if i simply make this an else statement
///if fireball reaches the end of the screen, bring it back to the ball
if(fireballShot>SCREEN_WIDTH /*&& fireballShot>SCREEN_WIDTH*/)
//^^^combine these two when I figure out initial second bullet problem [less code sake]
Thanks for the reply. The confusion is....h should equal 102 when I press space a second time and it doesn't for some reason. I end up having to wait until fireballShot [the 1st fireball] is greater than the screen width[line 40] AND THEN AND ONLY THEN h increments like it is supposed to. What happens in the program is when it starts I can shoot the first bullet, but not the second bullet no matter how many times I press space only until that 1st bullet crosses the screen. Then after that I can shoot both bullets. What I am going for is a player being able to shoot both bullets right off the bat.
The program does work if I change line 28 to just an else as I am able to let off two bullets right off the cuff just fine. I just really want to understand why.
EDIT: Got it. Thanks to anyone who tried this problem.