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 / Problem creating level

Author
Message
Homey
17
Years of Service
User Offline
Joined: 18th Feb 2008
Location:
Posted: 19th Feb 2008 04:52 Edited at: 19th Feb 2008 23:06
hi im new here, and im taking a computer science class. I was given a prototype and was given the task to add levels, texture, design, etc. right now im really frustrated and im unable to make more levels to this game. im pretty confused, can someone help me plz?

the file .dba is attached. Take a look at it and help me the best you can.
Thank u

re-EDITED: haha i don't know how to reply... since i couldn't find a reply button also but my main task right now is to add levels to it. If you could show me how, it would be greatly appreciated.

http://img114.imageshack.us/img114/5254/homie1fj7.jpg

Attachments

Login to view attachments
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 19th Feb 2008 20:14

Your tutor wrote that?!

For some reason it needs to load an object that is intriguingly called "box" , I replaced this with DBs own objects so no media is required


Your teacher seems like a pretty experienced programmer, but he seems to be a complete noob to DB, there's a lot of bad code in there and it's putting me off helping you.
I'm going out for a bit but when I come back I'll have a proper look at the code

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 19th Feb 2008 22:00 Edited at: 19th Feb 2008 22:17
Quote: "Your teacher seems like a pretty experienced programmer,"


What???

Quote: "if keystate( scancode() ) = 1 then goto OptionsSection"


I would be dismayed if a teacher on a course I was taking part in told me that I should use Goto while using a procedural programming language. It's basically inciting you to write spaghetti code!

It's OK to use Goto in very rare circumstances, but it is wholly avoidable 100% of the time. I have NEVER used it, but using it safely does require that you know exactly what you are doing. It should be avoided completely if you are a newcomer to programming.

So teaching a class using Goto is ridiculous - or the teacher doesn't really know what he/she is doing.

Likewise, setting the screen display inside the main loop (60 times a second) is also a real no-no.

Finally, what use is if keystate(scancode()) = 1? That will jump to the options section whatever key you press. Surely it should be tied to some specific key like the F1 key:



[Edit] Didn't spot the main program code - thought the Do..Loop snippet was all there was!

After looking at the main program, I agree with Obese - whoever wrote it doesn't know what he's doing with DB and the program was possibly converted from another dialect of BASIC.

Do..Loop is the slowest of the loops - and the most inappropriate for what they are being used many times for in this program.

Repeat..Until would be better better than Do..Loop, but a loop isn't even required. In DB rather than use:



you would use:

Wait Key

There are numerous loops better than Do..Loop - none of which have been used.

TDK_Man

Yodaman Jer
User Banned
Posted: 20th Feb 2008 16:42
Quote: "It's OK to use Goto in very rare circumstances, but it is wholly avoidable 100% of the time. I have NEVER used it, but using it safely does require that you know exactly what you are doing. It should be avoided completely if you are a newcomer to programming."


Could that possibly explain problems that I've had?

Quote: "Likewise, setting the screen display inside the main loop (60 times a second) is also a real no-no. "


Agreed. I think If I tried something like that it would crash my system. Reboot time!

Quote: "There are numerous loops better than Do..Loop - none of which have been used.
"


Agreed, although I am a noob. But I have studied and have found do..loop to be, for some reason, the only one I can remember to use!
Apparently I'm not the only one...
Great points TDK, I really had trouble translating the code myself. Probably because I haven't learned that much about functions yet, as I'm still working on pretty basic stuff...yrotate object 2,wrapvalue(object angle y)...that kind of stuff.



Thanks to BigAdd for the incredibly awesome sig!
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 20th Feb 2008 17:35
There are too many "rem`s" in the code. It makes me dizzy and I almost fell off my chair whilst studying your code.

This code



You could shorten to this:



Oooooops!!! I accidentally formated drive c.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 20th Feb 2008 21:49
Quote: "Could that possibly explain problems that I've had?"


Using Goto can cause anyone problems if not used correctly because it's a jump with no automatic return. If you don't keep a very close eye on the 'Program Counter', your program can get very tangled.

To demonstrate exactly what the Program Counter is, take the biggest program you have written and load it into the DB editor. Now run it in your mind - just as if you had pressed F5.

Starting with the first line, imagine what the DB code will do. Then go to the next line and do the same. Repeat for each line.

When you reach a Goto, Gosub or Function, jump to the correct line in your program and continue. The line you are currently on in is held by the Program Counter.

At the end of a procedure, you will see a Return and at the end of a Function there's an EndFunction. When you hit these, you jump back to the line in your program that you called the procedure or function and carry on with the line immediately following the call.

The Program Counter knows exactly where to jump back to in the program because when it reaches a Gosub or function call it places the current Program Counter value on the stack.

When it reaches a Return or EndFunction, it retrieves the value off the stack and uses it to set the Program Counter back to where it came from.

But you'll notice that with Goto there's no 'Return'. You are responsible for using another Goto to jump to a different block of code.

The problem is that you may forget to add one - or end up with lots of Gotos everywhere, leaping about all over the place. This is spaghetti code and is very hard to follow.

If you stick to procedures and functions this is just one less thing to worry about. You can have a basic empty skeleton .dba file which can be used to start every single DB project you ever write.

There's one here:

http://www.computechtenerife.com/layout.htm

TDK_Man

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 21st Feb 2008 23:14
I've used GOTO once! (since gaining a bit of experience anyway)
and that was because I had coded myself into a corner and there really wasn't a better way to jump out. All that shows is that I hadn't planned the code out well enough.

Login to post a reply

Server time is: 2025-06-04 01:47:45
Your offset time is: 2025-06-04 01:47:45