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 / gosubs becoming confusing, mixed up code debugging, i need fresh eyes

Author
Message
monstercameron
14
Years of Service
User Offline
Joined: 24th Dec 2009
Location:
Posted: 22nd Jan 2010 01:49
i have been slowly learning darkbasic by myself and its hard. i have been working on a game (right now called generic platformer V0.1) simple sprites, levels, audio, ai and a goal. the code wasn't really jumbled until i started using gosub to make it smaller. now it wont run, im no pro and i need help.(btw i was on here a few weeks ago and a dude really helped me out, im looking out for u, took ur advice, sorta...)

__init__.dba


varsheet.dba

loadsheet.dba


level1.dba


ai.dba

console.dba
* not doing any thing yet, so far i can open and close console with game still open,

debug.dba
* dont really use it anymore... for level and hero placemnet

main game loop
* works...


cant figure out how to accelerate, acceleration due to gravity or to smoothe out the movements.

i want to find out how to make a ghosting effect too.

most of the code is good it is the __init__.dba thats not fleshed out...

note this is for debugging.
i am open to tips and such, the more the merryier

guess what

Attachments

Login to view attachments
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 22nd Jan 2010 03:27
Hi, I'm not a pro at programming either but I do remember hearing somewhere that functions are better to use than subroutines and that using subroutines can result in spaghetti code. It will be a lot of work but you could try reprogramming your program using functions.

As for making a ghost effect you could play around with the 'Set Sprite Alpha' command.

Hope this helps

A clever person solves a problem, a wise person avoids it - Albert Einstein
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 22nd Jan 2010 04:28
You've gone too far!!! Stop with the gosubs!

Heheh, I don't really want to sift through code to find out where you're going wrong, but i say you just need to start over at a backup of your code. If you don't have one, then try to move it back somehow

What I usually do, is have one source file, with subroutines for repetitive or unimportant stuff (like loading stuff or minor unimportant initialization stuff), and functions for anything that accepts a value.

What's really weird is that you're using subroutines not declared in a .dba file, when they haven't been included. I'm referring to the sub_MAINLOOP subroutine. I'm not sure if you can do that or not, but it's definitely weird code. In my opinion, code split up into separate files with interdependent includes is very, very annoying to read and understand. Much better IMHO to have one source file, unless the file your including is fundamentally different.


HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 22nd Jan 2010 13:47
one way that might help is to put a lot of print statments in your code one say just before a gosub entering gosub name of gosub, then when hits the return of that gosub, print leaving gosub name of gosub.
You will end up with a lot or prints on the screen but you may just see where it goes there but not come back until it find the next gosub return.

Also another way is to look at the fullsource dump as this will show how the complier as put it all together.

Dark Physics makes any hot drink go cold.
monstercameron
14
Years of Service
User Offline
Joined: 24th Dec 2009
Location:
Posted: 22nd Jan 2010 15:27
functions are a bit difficult for me

guess what
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 22nd Jan 2010 15:57
Quote: "now it wont run"

It's a little hard for me to know how to advise you because I'm not sure how you have assembled all of your code together. Can you put all of your code into one CODE SNIPPET box?

Quote: "i want to find out how to make a ghosting effect too"

I would play around with the
SET SPRITE ALPHA Sprite Number, Alpha Value
command.

Quote: "cant figure out how to accelerate, acceleration due to gravity or to smoothe out the movements."

It seems that you have hard-coded your movement amounts. It would be better to assign a variable to the amount to move on the X and Y axis. You could do it using either an array or with TYPE variables also.

Quote: "I do remember hearing somewhere that functions are better to use than subroutines and that using subroutines can result in spaghetti code"

The use of subroutines in and of themselves will not tend to create spaghetti code IMO. A game could be coded using all subroutines and could be the picture of organization. Using GOTO will indeed tend toward spaghetti code (man, I hope this thread doesn't turn into a GOTO / NO GOTO argument). Functions can return a value, whereas subroutines cannot. Variables in a function are local unless declared otherwise as global. Variables in a subroutine are not local. There are some differences between functions and subroutines, but largely it is up to the programmer to decide which he/she will use.

Click my sig to download TGC Heroes v0.94.

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 25th Jan 2010 15:56
Quote: "Can you put all of your code into one CODE SNIPPET box?"


My guess is that would be difficult. Not sure, but it looks like every subroutine in his program has been saved as a separate dba file and been #Included.

I don't know whos help you've been getting, but I'm pretty amazed it ever worked. For a start, #Include, although still works, is now obsolete in DBPro.

As has already been said, scrap it all now! Restart it doing it the 'normal' way. You can get info on program layout and style here:

http://forum.thegamecreators.com/?m=forum_view&t=96075&b=7

TDK

monstercameron
14
Years of Service
User Offline
Joined: 24th Dec 2009
Location:
Posted: 6th Feb 2010 08:58
thanks guys i re-re-did my code and it now works , am now inteh process of getting the quality of images and audio in, and bug fixes.



guess what
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 6th Feb 2010 15:46 Edited at: 6th Feb 2010 15:48
Looking much, much better! A couple of thoughts:
1. Consider putting the loading all of your images into one subroutine.
2. Since you have a number of images to load, you might consider placing multiple images on a single bitmap and then grabbing the images in the code.
3. In the code

why is the EXIT command there? It is unnecessary.
4. Suggest you indent your code 2 spaces for each level. The above code would be more readable if it looked like this:

5. Your main do - loop is pretty long. It is best to compact the main do - loop (I prefer repeat - until myself) as much as possible. It makes for more readable code and it is easier to debug that way. Look at what you can take out of there and put into a specific subroutine, such as gosub UserInput, or something like that.
6. Your main do-loop ends with a return, which really should be an END statement. It is best to delete all of your media before exiting the program, so all sprites, images, music, sounds, objects, etc. should go. I would suggest using DISABLE ESCAPEKEY just before your main do-loop and check for IF KEYSTATE(1) = 1 THEN EXIT somewhere in the loop. Bear in mind that if your code hangs up in a subroutine, that you will have to CONTROL - ALT - DELETE to get out of it. Make sure your code is stable before you put this in.

Again, nice progress. Keep it up.

Login to post a reply

Server time is: 2024-09-28 14:27:23
Your offset time is: 2024-09-28 14:27:23