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 / question about variables

Author
Message
Calliah
21
Years of Service
User Offline
Joined: 14th Oct 2003
Location:
Posted: 12th Nov 2003 03:31
Hi,
I've been studying darkbasic for a few days now, but i don't have much time due to work. Most of my free day does go to studying, however. I've learned many of the basic commands, and I've also learned the use of them. I do have one question, however. The first section of code works like it should, creating shrinking boxes on the screen in different colors. The second section, however, will create boxes of different colors, but will not shrink them. I know that this has something to do with those variables, but i'm not sure. Is the subject of scope escaping me? Or is it something else? Help is greatly appreciated.
Thanks.
Sleet
21
Years of Service
User Offline
Joined: 3rd Aug 2003
Location:
Posted: 12th Nov 2003 04:14 Edited at: 12th Nov 2003 04:15
You're absolutely right about it having something to do with the variables.

Sometimes to find the bug you need to run through the program like your computer will. Lets look at the first one and why it works. We'll use one variable for simplicity

to start Left=0. Then you hit the for x=1 to 50 loop and you keep changing the value of Left every time you run through the loop with the command Left=Left+20 meaning that the first time you run through the loop Left=20, second time Left=40 etc.

Now for the second one and why it doesn't work.
You never change the value of Left. Left (according to your computer) always equals 0.

eg:
computer sees Left and asks "what is Left" Left=0(because that's what you told it it equals at the begining)
computer sees +20
computer does 0+20

computer goes through loop again
computer sees Left and asks "what is Left" Left=0
computer sees +20
computer does 0+20
Calliah
21
Years of Service
User Offline
Joined: 14th Oct 2003
Location:
Posted: 12th Nov 2003 04:23
Thanks a bunch. I was reading the reply, and as soon as i saw "you keep changing the value of Left", it just dawned on to me as to why it won't work. Ok, thanks a lot. I do have another question, since my problem with that has been solved. I'm making another line twirl all the way around the screen. I've got the code for it, but it seems a little repetitive, even with the loops. Aside from functions, is there anything that could/should be changed? The way i see it, if i am shown how the code i write should be changed, I'll understand coding more myself. Thanks again.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 12th Nov 2003 06:15
about halfway down there is an error:

LoopLeft = 0
Top = 240
Right = 640
Bottom = 240


needs to be

Loop
Left = 0
Top = 240
Right = 640
Bottom = 240

then it compiles and runs.
don't use this code as a how-to because it's not good. Code that works isn't always code that's good. Try and rewrite it's functionality in much shorter, neater, less redundant code...
There's a "lab" for ya

-RUST-
Calliah
21
Years of Service
User Offline
Joined: 14th Oct 2003
Location:
Posted: 13th Nov 2003 01:17
Odd. I just noticed that. I pasted the code once, but it showed up three times. It should look more like the code pasted here.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 13th Nov 2003 01:25
thats funny -


-RUST-

Login to post a reply

Server time is: 2024-11-25 16:57:29
Your offset time is: 2024-11-25 16:57:29