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 Discussion / Criticism

Author
Message
Wiley85
16
Years of Service
User Offline
Joined: 9th Jan 2009
Location:
Posted: 15th Feb 2009 16:25
As you know, criticism is essential to forward development, so I've posted my latest small project here for just that purpose. Please lemme know what you all think of any aspect of this bit of code. It's simple, but I think it serves its purpose well. Thank you everybody!

RYD
17
Years of Service
User Offline
Joined: 29th Apr 2008
Location: realspace
Posted: 15th Feb 2009 20:29
good for the IQ

ARM YOURSELF WITH KNOLEGE
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 15th Feb 2009 21:15
Two things:

1) What is this "PRINTC" you use? Is that part of a dll I don't have? I just changed to "PRINT" and it worked fine.

2) Somewhere in there, probably in the beginning, you should put a

in.

Let me explain.

When you use

rnd(...)

It's not REALLY picking a random number. What the computer is doing is it is generating a list of seemingly random numbers to use if you call it.

What

randomize

does is it does what's know as "reseeding" the random number generator. Got that? That means that it's just making a new list of numbers based on an integer.

When you add in

randomize timer()

you reseeding the random number generator with the integer that is in timer(). Let me explain one last time. Timer() is just a number stored by DarkBASIC that represents how long (in milliseconds) since the computer was turned on. You will learn to love this, as it at the heart of all timers.

In fact, I believe TDK_Man has a tutorial on it...let me find it.

Here ya go: http://forum.thegamecreators.com/?m=forum_view&t=59347&b=7

But otherwise, a great program. Good luck, and good coding!

~QJ
Ashingda 27
17
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 15th Feb 2009 23:31
It was hard for me to solve your problems even the additions.... It showed up and then disapeared befor I can see it .

Use mouse functions instead of the input statements.
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 16th Feb 2009 00:03
I think that's the point.

~QJ
Wiley85
16
Years of Service
User Offline
Joined: 9th Jan 2009
Location:
Posted: 16th Feb 2009 17:06
Thanks guys for the posts! I love to hear how I'm doin in my coding since I'm still pretty new at it.

A couple of things I should explain though I think.

First, the PRINTC code I just found in my dark basic v1.12 book towards the back in the hidden code section, among WAIT KEY, 3DS2X, ROTATE IMAGE, and MALCOLMBAMBER. I won't explain these codes in detail, but rather let you all use them and figure them out, as that's half the fun right? The PRINTC code just allows you to keep the cursor at the end of the print string instead of using a semicolon. So that's that.

Also, the reason the problem flashes so fast is to simulate the idea of those flash cards we all used as kids, only instead of making you solve the problem fast, you have to read it fast. I did try to put a timer on the answer input, but decided to leave it for now to gain some simple initial criticism. You will notice if you look at the code however that as you answer problems wrong, the amount of time the problem flashes increases by a tenth of a second. That variable is easy to change to make the problem easier to solve.

And lastly, I think the RND() command works just fine for this application since the compy is choosing from two separate blocks of fifteen numbers. I did notice the compy re-using some numbers quite frequently, but I guess that just makes the user use their memory as well as mathematical aptitude, which is a large part of math smarts. Also notice that with each run of the program, the numbers generated by RND() will change.

Anyway, I hope that answers questions or concerns any may be having with this bit of code. Keep posting to let me know what you think. Thanks again!
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 16th Feb 2009 17:42
Haven't had too much chance to try out the code, but from looking at it, I do have some pointers.

1. Indent your loops/subroutines. This makes it easier to read and it will even help you catch some mistakes. Here is what it would look like:

DO
PRINT "HI"+str$(counter)
INC counter
LOOP


Should be turned into:

DO
PRINT "HI"+str$(counter)
INC counter
LOOP

Notice that it is easier to see immediately where the beginning and ending of the loop is?

2. DIM random(15,2)
random(1,1)=RND(S*10) : random(1,2)=RND(S*10)
random(2,1)=RND(S*10) : random(2,2)=RND(S*10)
random(3,1)=RND(S*10) : random(3,2)=RND(S*10)
random(4,1)=RND(S*10) : random(4,2)=RND(S*10)
random(5,1)=RND(S*10) : random(5,2)=RND(S*10)
random(6,1)=RND(S*10) : random(6,2)=RND(S*10)
random(7,1)=RND(S*10) : random(7,2)=RND(S*10)
random(8,1)=RND(S*10) : random(8,2)=RND(S*10)
random(9,1)=RND(S*10) : random(9,2)=RND(S*10)
random(10,1)=RND(S*10) : random(10,2)=RND(S*10)
random(11,1)=RND(S*10) : random(11,2)=RND(S*10)
random(12,1)=RND(S*10) : random(12,2)=RND(S*10)
random(13,1)=RND(S*10) : random(13,2)=RND(S*10)
random(14,1)=RND(S*10) : random(14,2)=RND(S*10)
random(15,1)=RND(S*10) : random(15,2)=RND(S*10)


This can be simplified to about 4 lines. Guess how? That's right, LOOPS! Using a FOR-NEXT loop, you can change that to:

DIM random(15,2)
FOR i=1 to 15
random(i,1)=RND(S*10)
random(i,2)=RND(S*10)
NEXT I


And, since you use the exact same code in two other places, you could just call it once! Which leads me into number 3...

3. Subroutines. You appear to have read something about them, since you used the GOTO command (which usually is tried to be avoided). Subroutines are great because they help keep your code neat AND they can save you some time and trouble while coding. Think of subroutines like paragraphs on a page. If you need to reference something to someone, you just have to say "Go to the second paragraph". However, if the entire paper were one BIG paragraph, you would have to say "Go to that sentence somewhere in the middle that looks like..." which is MUCH less efficient.

Here is a framework for subroutines:

DO
INC COUNTER
IF COUNTER=15
COUNTER=0
GOSUB display
ENDIF
LOOP

END

REM VERY SIMPLE SUBROUTINE HERE!
display:
Print "Hello! It is currently Counter="+str$(counter)
RETURN



This is a simple subroutine but it demonstrates how they work. Using GOSUB, it will tell the code to jump to a subroutine with the given name (like GOTO). The difference between GOSUB and GOTO is the RETURN command. When used in conjunction with GOSUB, the RETURN command will return back to the next line of code AFTER the GOSUB call, so that it can continue the program, a feature GOTO lacks.

4. Main Loop. Your program lacks it, which makes everything harder on you, the coder. A trick I recently learned from Ashingda is to use a state variable to control where to go and have EVERYTHING done in 1 DO loop at the beginning, like so:

DO
IF State=1 THEN GOSUB STATE_1
IF State=2 THEN GOSUB STATE_2
`ETC ETC ETC
LOOP

END

STATE_1:
PRINT "The state is now 1!"
State=2
RETURN

STATE_2:
PRINT "The state is now 2!"
RETURN

This will also completely eliminate the need for goto commands, since you can just change the state to what you want and it will go there for every loop until state changes again. It makes it VERY easy to restart a program.

Thats all for now. Hope it helps and I will tell you more if I think of it!

Good luck!

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Wiley85
16
Years of Service
User Offline
Joined: 9th Jan 2009
Location:
Posted: 18th Feb 2009 01:28
Okay, I've applied the changes recommended by BN2 productions and this is what I've come up with.



Does that look like what you were talking about?
gearce
18
Years of Service
User Offline
Joined: 18th Dec 2006
Location: ex SCOTLAND, now MELBOURNE, Australia
Posted: 18th Feb 2009 07:55 Edited at: 18th Feb 2009 08:33
BN2 Productions

Quote: "
1. Indent your loops/subroutines. This makes it easier to read and it will even help you catch some mistakes. Here is what it would look like:

DO
PRINT "HI"+str$(counter)
INC counter
LOOP


Should be turned into:

DO
PRINT "HI"+str$(counter)
INC counter
LOOP

Notice that it is easier to see immediately where the beginning and ending of the loop is?"


They both look the same to me.

gearce

LANG MEY YER LUM REEK

You must be the change you wish to see in the world
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 18th Feb 2009 23:19
It's just that they ARE, but they AREN'T.

You can indent in the window to post, but - unless you're in a code tag - it wont indent.

~QJ
gearce
18
Years of Service
User Offline
Joined: 18th Dec 2006
Location: ex SCOTLAND, now MELBOURNE, Australia
Posted: 8th Mar 2009 10:37
OK


gearce

LANG MEY YER LUM REEK

You must be the change you wish to see in the world
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 8th Mar 2009 10:50
I thought I did code tag, OOPS!

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 9th Mar 2009 01:10
BN2 has covered everything I can see .
This looks like the stuff I used to write in QBasic, glad to see I'm not the only one who thought jumping through lots of GOTOs was a good idea

Subroutines are much better, you can call them from anywhere and you'll return to that spot, with gotos you have to tell the program where to go next.

@quirkyjim
Quote: "1) What is this "PRINTC" you use? Is that part of a dll I don't have? I just changed to "PRINT" and it worked fine."

PRINTC prints on the same line as the last print, or it doesn't carriage return after printing. One of the two.

The Universe has been erased by a mod because it was larger
than 240x80 pixels.
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 9th Mar 2009 23:09
Yeah, I happened to find all the hidden command posts right after I posted this.

~QJ

Login to post a reply

Server time is: 2025-05-16 20:15:31
Your offset time is: 2025-05-16 20:15:31