Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / I'm going slowly crazy...

Author
Message
Dar13
18
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 19th Jul 2010 17:49 Edited at: 19th Jul 2010 17:52
Okay, I've got this really annoying bug in my Space Invaders clone and it seems so simple to fix but DBPro seems to have lost the ability to do greater than or less than comparisons in if statements!

Here's my code causing the problem:


With player.positionX=400 and enemy(i).positionX=209, the program still manages to get to the for next loop.

I'm at a total loss as for why this should happen, any suggestions?


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Jul 2010 18:34
Two comments:

1. You seem to be using the variable "i" for two different things - the index for the enemies before the loop and the index for the for/next loop. That could screw up all sorts of things. Use a different variable for the index of the for/next loop.

2. Did you try printing the values of enemy(i).positionX and player.positionX immediately after the "if"?
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 19th Jul 2010 18:35
Look at it again

What is player.positionX? Did you want to have enemy(i).positionX?

....and yes... I go crazy slowly too....

The fastest code is the code never written.
Dar13
18
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 19th Jul 2010 21:16
Quote: "1. You seem to be using the variable "i" for two different things - the index for the enemies before the loop and the index for the for/next loop. That could screw up all sorts of things. Use a different variable for the index of the for/next loop."


That was the problem right there. It was using the second i variable instead of the first one so I was accessing enemy(0) for the positioning of the projectile. Thanks for the help Green Gandalf


Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 20th Jul 2010 03:59
WOW. My post was WAY OFF. I saw it backwards! Please ignore what I said. I usually don't miss this kind of stuff.

The fastest code is the code never written.
Dar13
18
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 20th Jul 2010 22:47
It's alright Hawkblood.

Thanks for trying to help in any case.


Login to post a reply

Server time is: 2026-07-25 05:32:51
Your offset time is: 2026-07-25 05:32:51