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 / "Tear my code apart"

Author
Message
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 27th Aug 2009 07:05 Edited at: 28th Aug 2009 04:20
I would like to know what I could improve on:
-code structure and neatness
-code useage
-graphics(no media)

Thanks!



This is non-media but will create a file if you save in level editer.(The reset button erases the file.)

Without caffeine, where would our awesome programers be?
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 27th Aug 2009 07:20
Haven't run it, but I noticed at least 2 loops in there. One was your main program loop the other was for the menu loop.

Rhetorical question:
How do you go back to the menu?

Rhetorical Answer:
Not as easily as it could be!

A better format would be something like this:



Short but sweet. Then in each subroutine you put everything that would go in a loop (but don't use any loops).

The benefit to a system like this is that it is VERY easy to reset, you just reset your State variable to whatever you want it.

If you want to improve the intuitiveness of that code as well, you could set some variables equal to constants, such as MENU=1 and so forth. That way you could write:

STATE=MENU

and it would do the same thing.

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
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 28th Aug 2009 01:03 Edited at: 28th Aug 2009 01:12
@razer
i don't like those subroutines that call other subroutines, and some even have labels within them making it all a bit messy.

It's also not very intuitive, as bn2 said, your "gosub mouseclick" doesn't tell the reader anything and may as well say "I don't care where you go just get the hell out of my main loop!"
It's better to have lots of subroutines that do a clear and specific job than squeezing them into one generic messy sub.

Quote: "if rndX(3)=rndX(1) and rndY(3)=rndY(1) and n=3 or rndX(3)=rndX(2) and rndY(3)=rndY(2) and n=3 then goto back"

Long lines like this can and should be avoided, but bn2 deals with that.

the general layout is ok and indentation is mainly ok, comments need indenting too.
you just need a bit of practice to get the most out of subroutines.
look at experienced people's code and you'll see how they divide up their programs.

TGC Forum - converting error messages into sarcasm since 2002.
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 28th Aug 2009 02:42 Edited at: 28th Aug 2009 04:20
Thanks I'll work on those stuff.I'm trying to get better at this neatness thing.

@BN2

There are also these loops:



I use these so I Can wait for a little bit while still pasting the moveing background.How would I get past things like that?

And one reason I use gosub's in gosubs is because I don't want to paste the images sepretly in each gosub.But I do only use one DO LOOP in the program and I lable it.I see what you guys mean tho.

Without caffeine, where would our awesome programers be?
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 28th Aug 2009 03:35
that's a horrible loop, why are you making db check something that never changes? and why use exit in a conditional loop?
sorry if i sound harsh but you're bending the right commands to use in the wrong way; you even chose while over repeat which is perfect, but you didn't use the condition properly.

TGC Forum - converting error messages into sarcasm since 2002.
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 28th Aug 2009 04:12 Edited at: 28th Aug 2009 04:27
Quote: "that's a horrible loop, why are you making db check something that never changes?and why use exit in a conditional loop?"


Well for one I use WHILE and REPEAT loops as like mini loops.For two when I put:



It would flash because it cleared the screen before it exits.So I put that so it would not flash.

But if you look at my parachute game and this game you can tell the diffrence, so I'm improving...veeerrry slooooowwwwwlllyyy....

I'll just think every line of my code,"What would Obese say about this?"

If there's anything wrong with the game tell me, thx.

Without caffeine, where would our awesome programers be?
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 28th Aug 2009 08:06
You could even replace the while loops with a subroutine called from the main do loop and a single if. So:


while that is useless it could be re-written as



This is an EXAMPLE of the layout, but it is pretty bad code. Just to point out my own flaws here, the last 2 lines of Hello: could simply be replaced by

State=rnd(1)

and it would do the same thing. However, I put the IF in there to demonstrate the concept here. Once again, this is good for modularization and (more importantly) there is less chance of a infinite loop in a system like this. An infinite loop is where it will keep going (so if your condition is while I>0 it would be if for some reason I is constantly decreased or something). These are usually very difficult to track down, but with a state variable, you can open the CLI and print the value of state and you will know EXACTLY where you are and what is going on.

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
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 28th Aug 2009 20:04 Edited at: 28th Aug 2009 20:10
@BN2
I quite like that state system it's very modular and would be simple to edit the program. I imagine it would be good for something like an rpg maker.

@razer
why do you draw the images over and over for 1.5 seconds?
Quote: "I'll just think every line of my code,"What would Obese say about this?""

don't worry, if I thought you were useless I wouldn't post anything.
The harsher I am, the better I think you are.

TGC Forum - converting error messages into sarcasm since 2002.
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 28th Aug 2009 23:53
Quote: "why do you draw the images over and over for 1.5 seconds?"

the back ground moves constantly so I can't use the SLEEP command.(just play the game to see).

@BN2

Why not just put this:


Why make it random?

Without caffeine, where would our awesome programers be?
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 29th Aug 2009 08:35
I was going for keeping it similar to the code I used in the first case. Again, IGNORE THE CODE, look only at the idea/structure of it. The code is horribly written and should have nothing pulled from it other than the structure I was suggesting.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 8th Sep 2009 23:24
Next>



A good game is one percent inspiration, ninety-nine percent perspiration.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 9th Sep 2009 02:10
Quote: "A good game is one percent inspiration, ninety-nine percent perspiration."

Very true, although I've only ever gotten through about 30% of the perspiration bit

TGC Forum - converting error messages into sarcasm since 2002.
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 9th Sep 2009 02:15 Edited at: 9th Sep 2009 02:17
Ya, I've done that on a few projects now get a great idea and just get bored 40% through.

So, is there anything wrone with the code?

A good game is one percent inspiration, ninety-nine percent perspiration.
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 9th Sep 2009 02:16
Quote: "Quote: "A good game is one percent inspiration, ninety-nine percent perspiration.""


Perhaps why some programmers smell really bad?

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 9th Sep 2009 02:19
You guys know that's mostly from Thomas Edison right?

Quote: "Genius is one percent inspiration, ninety-nine percent perspiration."


Just want to make sure.

A good game is one percent inspiration, ninety-nine percent perspiration.
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 9th Sep 2009 02:53
yeah but it has been re-purposed many times over the years.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose

Login to post a reply

Server time is: 2024-05-01 23:39:33
Your offset time is: 2024-05-01 23:39:33