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 / Structuring your code?

Author
Message
Big Man
19
Years of Service
User Offline
Joined: 4th Feb 2005
Location: BEHIND YOU!!!! (but I live in England)
Posted: 29th Jan 2006 17:21
Hi
I know I frequent this forum and I have been programming for quite a while but there is something that I have never got the hang of.

Whenever I start programming I always structure my code in the wrong ways so half way through I have to go back and start A whole section again and this means that coding an entire game takes a long time.

So I would like to know If anybody could give me a tutorial on how to do this effectivly.

thanks

BM

Our aim is to keep the loo's clean, your aim can help.
General Sephiro
19
Years of Service
User Offline
Joined: 27th Sep 2004
Location:
Posted: 29th Jan 2006 17:25 Edited at: 29th Jan 2006 17:26
Heh go to the same college i went to, u'll never forget how to indent ALL your code

it just goes hand in hand with good practice

Edit - You could probably write a program to indent your code for you. All you require is to find an if statement then look for it's endif then tab out any information inbetween that...

Same with Loops blah blah blah

Image All
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 29th Jan 2006 17:56 Edited at: 29th Jan 2006 17:57
You mean people don't like pressing TAB? I can understand when it gets annoying to have to go *tab-tab-tab-tab-tab ...type... -return- tab-tab-tab-tab-tab* if the text editor doesn't automatically keep your tabs, but if people don't like having to manually indent once, then that's what I call being lazy

Big Man
19
Years of Service
User Offline
Joined: 4th Feb 2005
Location: BEHIND YOU!!!! (but I live in England)
Posted: 29th Jan 2006 17:58 Edited at: 29th Jan 2006 18:06
thanks for the help but I'm not that good.
And I dont think I used the right word.

I'll give an example.
At the moment I am making a fps game at the start I did the player movement the only way I knew how (The same way as in the monster hunt tutorial) but this clashed with the collision code someone gave to me.
I also attached the gun to the camera using lock object on but this clashed with the shooting and intersect object comands.

Could someone help me to prevent this sort of thing happening.

thanks

BM

Our aim is to keep the loo's clean, your aim can help.
harggood
21
Years of Service
User Offline
Joined: 9th Apr 2003
Location: the forest
Posted: 29th Jan 2006 18:33
Quote: "I also attached the gun to the camera using lock object on but this clashed with the shooting and intersect object comands."


Set object collision off for the gun?

Awfuldark Forest
Big Man
19
Years of Service
User Offline
Joined: 4th Feb 2005
Location: BEHIND YOU!!!! (but I live in England)
Posted: 29th Jan 2006 18:38
Oh no thats all sorted now I just wanted to know whether or not it is possible to know how to arrange your code to stop this sort of thing happening.

Our aim is to keep the loo's clean, your aim can help.
Fox Dark Master
20
Years of Service
User Offline
Joined: 20th Jul 2004
Location: Portugal
Posted: 29th Jan 2006 19:59 Edited at: 29th Jan 2006 20:07
How to structure you code

1 - Indentation
All the code should be indentate to be easy to read and/or edit
ex:

2 - Declaring Variables





KiTsUnE wOrKsHoP
Don Malone
21
Years of Service
User Offline
Joined: 27th Apr 2003
Location: Birmingham, Alabama
Posted: 29th Jan 2006 20:01
You will always benefit from roughing your ideas out on paper before coding the first line. This allows you to sit down and figure out what your needs are in the program.

That being said though; you will always have to make changes for things that don't always work as expected. Unless you are gifted or know the language inside out; you will always hit that wall. Even if you do know it that well; you may still try to squeeze every frame or effect out of your engine, and still have to change your code later.

But an outline of your program may help you think about the whole; instead of focusing on one module (section) at a time.

In Memory of My Dad.
I miss you very much.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Big Man
19
Years of Service
User Offline
Joined: 4th Feb 2005
Location: BEHIND YOU!!!! (but I live in England)
Posted: 29th Jan 2006 21:59
thanks guys this really helped.

Our aim is to keep the loo's clean, your aim can help.
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 30th Jan 2006 15:12
Its always good to create functions for as much things as possible, that way instead of having to change all the code you usually only have to change the parameters you use to call the function. The actual function code wont clash with other code so it makes debugging a lot easier. Eg if you get an error you cant figure out, delete a function, recompile, if the error is gone you know it was in that function.

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 30th Jan 2006 20:17
I would just rem off the function call and "remstart" and "remend" rather than deleting the function. Just in case something goes horribly wrong and the code is saved with the deleted changes.


Login to post a reply

Server time is: 2024-09-24 15:31:43
Your offset time is: 2024-09-24 15:31:43