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.

Newcomers DBPro Corner / Wierd bug/faulty coding on my part regarding data stored in a variable

Author
Message
Goatpuzzle
21
Years of Service
User Offline
Joined: 12th Jun 2003
Location:
Posted: 13th Jun 2003 21:22 Edited at: 13th Jun 2003 21:32
Ok, I've had DBP for a few months now but just finally got around to installing it the other day. I decided to make a slightyly altered version of the rotating cube proggie for my first project. However, I've noticed that when pressing down or right enough to reach the bottom value, it ends up being set to the high value rather than bottoming out. I'm guessing that the compiler is somehow getting confused and running the greater than lines when the less than conditions are met, but then this is my first DB prog and I may be messing something up... :-s


MAKE OBJECT CUBE 1,100
x#=0.1
y#=0.1
DO
if x# > 0.5 then x#=0.5
if y# > 0.5 then y#=0.5
if x# < 0.1 then x#=0.1
if y# < 0.1 then y#=0.1
YROTATE OBJECT 1,OBJECT ANGLE Y(1)+x#
XROTATE OBJECT 1,OBJECT ANGLE X(1)+y#
IF leftkey()=1 then x# = x#+0.01
IF rightkey()=1 then x# = x#-0.01
IF upkey()=1 then y# = y#+0.01
IF downkey()=1 then y# = y#-0.01
LOOP
Flashing Blade
21
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 13th Jun 2003 22:02
what effect are you trying to acheive because it runs exactly has instructed ie:

if right key is pressed then decrease x# by 0.01
then if x#<0.1 make x# 0.1
then add x#(always at least 0.1) to the object x angle.

ditto down and y#

so the loop adds a minimum of 0.1 or a maximum of 0.5 to the y and x angles every loop.
Goatpuzzle
21
Years of Service
User Offline
Joined: 12th Jun 2003
Location:
Posted: 14th Jun 2003 07:38 Edited at: 14th Jun 2003 08:13
Oh yes, I'm not disputing that it does what's intended, it's just that when I run it if I were to hold down right or down, it "stutters", if you will - whereas holding up or left produces no such effect. Upon investigating, when I press down or right to an extent where either x or y would be less than .1, it sets them equal to .5 in the opposite direction instead of .1.

-edit-
... ooooh, LOL, I know what I did wrong now. In fact, seeing what the problem is, I'm surprised this program did what the heck I wanted it to in the first place. I really have no idea why it was working. The code should be something like:

MAKE OBJECT CUBE 1,100
x#=0
y#=0
DO
if x# > 0.5 then x#=0.5
if y# > 0.5 then y#=0.5
if x# < -0.5 then x#=-0.5
if y# < -0.5 then y#=-0.5
YROTATE OBJECT 1,OBJECT ANGLE Y(1)+x#
XROTATE OBJECT 1,OBJECT ANGLE X(1)+y#
IF leftkey()=1 then x# = x#+0.01
IF rightkey()=1 then x# = x#-0.01
IF upkey()=1 then y# = y#+0.01
IF downkey()=1 then y# = y#-0.01
LOOP

And upon running the above code, it works just fine. LOL!

Login to post a reply

Server time is: 2024-09-20 12:34:04
Your offset time is: 2024-09-20 12:34:04