|
I'm trying to use a While loop to stop the player when he is looking at a wall, but when the player does look at a wall the game crashes, From what I found on my own, if a while loop doesn't have an exit it will become an infinite loop, which is what crashes the game, I'm assuming that the Else statement I made is not doing anything and that's the problem, however I don't know what to use to replace it.
(comments are locked)
|
I do not see why you want a while() there, try an if() If I use an If it will set the speed to 0, and then it will stay 0. Edit: I went and put in an else that resets the speed and it worked. Thanks!
Jul 17 '12 at 09:29 PM
Mattchuuu
No problem, knew you would figure the rest
Jul 18 '12 at 08:39 AM
Linus
(comments are locked)
|
|
This is unnecessary: You can use: You don't need a while loop to change a speed value to zero, you set it to zero once and the object should stop moving, in fact take out and replace it with It sounds like you're trying to implement collision detection before you have a basic understanding of how program flow works. Please start by doing some programming tutorials before trying game development, it will save you alot of frustration. My problem is that if i just set it 0, it stays at 0 permanently. I only want the speed to be stopped while it's looking at the wall. I wanted to try using a while loop because then by my understand, while the boolean is true it'll set the speed to 0, and when it's not it'll set it back to normal.
Jul 17 '12 at 09:32 PM
Mattchuuu
However you haven't posted any code that sets speed to anything but zero. Even setting the speed to something besides zero just before the code you posted will give you exactly what you need, because speed will be set and then your code does it's check which will zero out speed if-and-only-if we hit a wall. Like I said, you're having program flow issues that would be resolved with basic tutorials. Have you for instance done "Hello World" tutorials for any language before? That sort of stuff prepares your sense of logic for more advanced projects.
Jul 17 '12 at 09:39 PM
Muuskii
(comments are locked)
|
