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 / A Couple Questions From A Newbie

Author
Message
clakes707
12
Years of Service
User Offline
Joined: 2nd Feb 2012
Location:
Posted: 17th Sep 2012 10:22
Alright so I'm pretty new to DB. So far, in working on my "game"(which is more of basically a learning feature test), I have been able to make a player character(in top down view) that is able to face the mouse, and be moved around with WASD. Before DB, I used and still do, Game Maker 8. The differences between Game Maker and DB are making DB somewhat confusing to me. So, here's a few questions I have:

1. Game Maker makes the game creation process visual, whereas DB does not. How can I organize my code, to make it easier for me? for example:



All of the main code, as far as gameplay-wise goes in the do loop, am I right? Well how can I organize this code, to make it easier to read? And does it matter what order the code is in?

2. I know I said I have a few questions, but I can't really think of any more right now. I think my main problem is I just need to learn more of the syntax and functions, and practice using them and seeing how they work. I will edit this post if I think of any more though.

Thanks for any help anyone gives me. Oh, and the above code, if it is of any use to anyone, feel free to use it. T
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 17th Sep 2012 21:28 Edited at: 17th Sep 2012 21:30
Quote: "How can I organize my code, to make it easier for me? "

I use the classic tried and tested functional route. That means I try to place all the blocks of code I call in relevantly-named functions and I try to make them dynamic and re-usable because it actually makes life easier in the long run.

Quote: "All of the main code, as far as gameplay-wise goes in the do loop, am I right?"

I recommend a set of functions for that, eg:


This is a very crude template but it's the general idea of "breaking it up into smaller components". Two other tips is to use UPPERCASE FOR KEYWORDS when coding in basic and to mark variables with some meaning. For example, I often use the prefix c_ for CONSTANTS (which are not variables technically) and the prefix g_ for globals so I can easily see what a variable's scope is (ie: no prefix = local). Ultimately you should format how it looks best to you (for example my Function/EndFunction blocks are always proper case even though all other keywords are uppercase. I use lowercase only for most variables. I usually double-indent (6 spaces) when coding in BASIC because I place keywords in uppercase. Comments are very useful too, eg:


It all boils down to what you are comfortable with and what pleases you aesthetically (with me, my style is affected by my mood, lol!). I think we find our own style over time though.

Kiaurutis
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location: Lithuania
Posted: 30th Sep 2012 22:56
First of all I disabled "automatically insert closing block statement" in options>text editor, because it messes your code really bad.
Now if you want some advice about how to make your code easier to read and debug, I can explain how I manage my code. But it doesn't mean you have to do the same.

1) You can divide your code into a few source files: main.dba for main program, PlayerControl.dba for player, LoadStuff.dba for loading Your content and so on. It is easier to find your functions this way, but I am not using this because when you get a runtime error, it doesn't show you the right line of error. Or at least it doesn't work on some old version of compiler that I was using year ago.

2) As nonZero mentioned, reusable functions are necessary. I started learning DBP by making an RTS game. It is not finished, but I rewrited everything in different structure for 3 times. Now I am up to RPG style game, and I used lots of functions from RTS. Something like setups, loading maps, selecting, moving objects- it is all reusable.

3)If you write a long long function, try to break it into smaller pieces. It will be easier to debug, because You need to find a problem in shorter piece of code. In 40 lines length function there may be many dependancies, many variables, if statements and other stuff. But you can cut away some code and place it in separate function. Then it will be easier to track down the bug, and code will be easier to read as You have less nested statements

If You have any nabish questions, I will be happy to answer. I can provide some code snippets too. For RTS or RPG. Control of objects, menus, loading media...

Here is a summary of my current project:



Join The dark Side! We have cookies

Login to post a reply

Server time is: 2024-11-22 00:05:01
Your offset time is: 2024-11-22 00:05:01