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.

Author
Message
misifield
18
Years of Service
User Offline
Joined: 23rd Nov 2007
Location: ohio
Posted: 4th Oct 2011 02:45
Hello, I am making a very simple low graphic RPG type game. I have tried several times to make this same game but always run into a problem eventually because I can not write organized code or think of better ways to create variables. Are header files good for organization? Like one header file would be monsters, one header would be items? The last time I tried to use header files I failed. Can anyone give me a few good tips on this please. Check my code out also so you can see what I am talking about, can you give me suggestions on how to create a structured/organized code.


mfield
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 4th Oct 2011 12:08 Edited at: 4th Oct 2011 12:11
Quote: " I have tried several times to make this same game but always run into a problem eventually because I can not write organized code or think of better ways to create variables."


Ironically, I think you are having an issue because you think as a programmer coming from a more structured environment. While DBpro provides some structure, it is a bit limited. I tend to face the same issues coming from a C/C++ background. While DBpro provides User Defined Types,, and you can have an array of a UDT, you can't have an array in UDT, or an array of UDT's inside another array. This mixed with the fact that functions are separate from the data, and the native pointers are cumbersome and I think confusing for many (memblocks anyone?); all adds to a problem for people who like to have things very neat and organized.

So we resort to techniques like parallel arrays and lots of global data, less declaring of variables and such. In the end we have a fairly modular approach held together by little bits and pieces everywhere. While I agree that it's good to maintain as much orginization as possible, I think that in a basic language we have to loosen the reigns a bit.


I think it's a good idea to break up the code into multiple files, and use a scheme/convention that fits your style best.


That said, even a low graphic RPG game can require a lot of data and gamestate flag manipulation. Something that I think can easily make BASIC code get messy in a hurry. Utilizing a scripting language (either of your own or something like Unity that has a plugin for DBpro) may ease the hard-coded logic. (I'm not skilled in script code, and it's why I steer away from the demand an RPG places on a developer). Also, I can imagine the need for some form of either a DataBase or at least the parsing of an XML file to help keep data somewhat organized.

Your signature has been erased by a mod please reduce it to 600 x 120.
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Oct 2011 15:27
Code shouldn't really by organised by object/entities, that is organised in the data structures you implement. Trya top down approach to organise, and make each part a sub/function...

1. Menu
2. Options
3. Play
4. Exit

Then break down at the next level, let's take (3)

3.1 Initialise game
3.2 Start Game
3.3 Play Game
3.4 End Game
3.5 DeInitialise

Then down a another level using 3.3....

3.3.1 Check Player Actions
3.3.2 Check Opponent Actions
3.3.3 Check environmental objects

etc...

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 4th Oct 2011 16:09 Edited at: 4th Oct 2011 16:09
Heres a structure I've used in the passed:

Program Structure (Top Down)
- Core Constant for are program
- Core UDT's
- Core Delcare (globals)
- Class Declares
< SYNC ON >
- Core Setup
- Class Setups
< Initialize Loop >
> Within Game States (because some classes might not need updating until in a certain state) >
- Core Updates
- Class Updates
< SYNC >
< End Loop >
- Clear All Data (to prevent memory issues)
< End Program >
- (Core/Class Structure Go Here)

Class Structure (Top Down)
- Constants
- UDT's (User Defined Types)
- Declares
- Setup or Initials (After SYNC)
- Function Set For Are Class¬
- > Creator/Operator Functions (ex. Create Object)
- > Update Functions (ex. Update Object)
- > Arguments Functions (ex. If Object Exist)
- Misc (Data Statements or Other Gosubs)

The classes would be modular, so in there seperate source file depending on project size.
misifield
18
Years of Service
User Offline
Joined: 23rd Nov 2007
Location: ohio
Posted: 4th Oct 2011 22:47
Thanks for the help! I think these ideas are going to help me. I have scrapped my original project and Im going to start over on a new foot.

I have never tried networking a game and I want this one to be networked. Is it possible to network the game after I get everything setup? Would this make it harder to make it networked? Can the client/server be coded into the same project?

mfield
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 4th Oct 2011 23:15
The way I work on things is I generally set the game itself up before I implement multiplayer code. However, with that said, it's a good idea to design the game around the fact you will include multiplayer capabilities later on.

The most important thing to think about when you have a networked game is that you can't pause in the main loop at all (Sorry... no WAIT KEY or SLEEP commands allowed!). The reason for this is so that your game doesn't miss any incoming packets being sent to it.

How you'd want to make your game is in a way such that the main loop never stops, or you don't get stuck in another loop waiting for user input.

Let me explain it this way: Say you have your normal game subroutine, your event subroutine, and your multiplayer subroutine. You also have a global variable, an integer labeled "event_on" which is by default 0.

Say in your game you walk up to a NPC and decide to talk to it. You can't just pause your game when talking to the NPC... when it registers that you talk to the NPC, you set "event_on = 1".

And here's how that will play into our main loop:




start_dialog_timer and end_dialog_timer are important, as they keep the spacekey from reacting more than one hit. start_dialog_timer is pretty much:

start_dialog_timer = TIMER()

And is set when you talk to the NPC and set event_on to 1.

end_dialog_timer gets checked in your normal gameplay routine to make sure you didn't just talk to the character less than a second ago, in the same fashion start_dialog_timer works.

Also, yes... the client/server can be coded in the same project.
misifield
18
Years of Service
User Offline
Joined: 23rd Nov 2007
Location: ohio
Posted: 5th Oct 2011 00:17 Edited at: 5th Oct 2011 00:23
Thanks for this information. I will go ahead and make the game before networking it.

Do you know if functions can be created in array and stored in text files. An example of this is having a healing potion.
item(1).name="Potion"
item(1).use="if player(num).hp<player(num).hpmax : player(num).hp=+10 : if player(num).hp>player(num).hpmax then player(num).hp=player(num).hpmax : endif"

then in the code I could do
if mouseclick()=2 then item(1).use

I am working on making a textfile system to where I create an item in game, it makes a text file, so if this works I can make special use items within the game without having to open up DBP and coding it in. This would help me organize my code because I would not have to scroll through thousands of lines, I would just open the textfile, or create an ingame system that shows me the variables for the file. How would I make a textfile that has code that can be used after storing it into an array?

This is my new organized code, after taking everyones advice. If I am in the middle of coding, I will make a new sub for the thing instead of adding it into another sub. I think this is a problem for me and possibly why my code gets messy.


Some of my subroutines are going into a header file for better organization. I managed to get headers to work this time. My admin function is where the creations of npcs, items, and maps are going. I do not have much in the headers yet so I didnt add them.

mfield
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 5th Oct 2011 00:45
Unfortunately you can't use textfiles like that, unless you want to make a parser that would tokenize those commands, then go through and check against of list of possible tokens then if a token matches, then run the associated code, but that is quite a bit of work for something like this... it would pretty much be like creating your own scripting language.

Login to post a reply

Server time is: 2026-07-11 14:37:15
Your offset time is: 2026-07-11 14:37:15