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 / Hi, I'm new and would like some help

Author
Message
Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 22nd Aug 2006 04:00
Hi.

I've been programming for a few years now but have found it complicated to complete 3d games in DarkBasic, so I'm starting in 2d. I've been reading the forums and learned the 2d commands, but have some questions before I code my tile-engine any more:

How much error checking is needed while reading from a file? Right now I have functions that check if a file is in the right syntax, but the calls make the code less readable, and if I make a map editor, it shouldn't be writing to the file wrong in the first place.

Should I define the image and sprite id numbers using constants or let a function generate them? I have allocated some id numbers to the engine because it makes it much easier to refence them, but that means the rest of my program will have to avoid using those numbers. I don't know if I should use a get_free_sprite() or get_free_image() function to get an unused id number, because that would make refencing those images more complicated and slow, but would simplify and speed up coding the rest of the game.

Any help would be appreciated.
Gil Galvanti
19
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 22nd Aug 2006 05:56
Welcome to the forums!

Although I don't work with 2D, I'll try to help you, because your one of the best noobs I've seen in a while .

Quote: "How much error checking is needed while reading from a file?"

On this one I'm confused on what your asking. What exactly are you trying to write to the file? File's don't really have a syntax, as far as I know, unless your trying to read DBP code from it (and by the way I'm assuming you mean like a text file or a custom game file?). If you could clarify this one more I'd be glad to help .

Quote: "Should I define the image and sprite id numbers using constants or let a function generate them?"

Really your choice, like you said yourself advantages and disadvantages to both. With declaring them it would be easier to keep track of but would take longer and possibly cause some numbers to be skipped or unused. If you declared them in a function, it would be better if you were deleting and making these sprites in the game because it'd be the easiest way to find a free number, but it would also be harder to keep track of .

Good luck, feel free to ask more questions .

Pirates of Port Royale
Live the life of a pirate.
Whisper Wind
21
Years of Service
User Offline
Joined: 5th Apr 2003
Location:
Posted: 22nd Aug 2006 07:53
Quote: "How much error checking is needed while reading from a file? Right now I have functions that check if a file is in the right syntax, but the calls make the code less readable, and if I make a map editor, it shouldn't be writing to the file wrong in the first place."


It depends, its really just your choice. Because the files are going to be generated by a map editor, I really wouldn't worry about it. The best you're going to do is stop your program from crashing due to a corrupt file, and at that point what can you really do anyway? Therefore I wouldn't really worry about checking for syntax. I might, however, check for missing content, broken links, etc... Could be useful debugging information if you do check it.

Quote: "Should I define the image and sprite id numbers using constants or let a function generate them? I have allocated some id numbers to the engine because it makes it much easier to refence them, but that means the rest of my program will have to avoid using those numbers. I don't know if I should use a get_free_sprite() or get_free_image() function to get an unused id number, because that would make refencing those images more complicated and slow, but would simplify and speed up coding the rest of the game."


It seems to me that if you're going to make a program of reasonable size, you pretty much have no choice but to figure out a system for tracking images and sprites and their numbers. Hardcoding it would be difficult, if not impossible for larger, more dynamic programs where things are constantly appearing and getting destroyed. How you do it is entirely up to you, but abstracting this part of the programming process makes a lot of sense to me. As for the speed issue, I wouldn't worry about it: if you code it right its just an extra function call, it should be nothing compared to the more complicated logic of your program. Besides you're going to write your program in 2D, if performance is a problem it means you're not writing very efficient code in the first place.

Searching for files named 'sanity'...
No files were found.
Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 22nd Aug 2006 19:43 Edited at: 4th Sep 2006 01:16
The files I'm talking about hold the map data. Now, they only hold which images are on the map, which tiles show which images on them, and whether a tile is walkable or unwalkable, but I have more planned.

Quote: "
Because the files are going to be generated by a map editor, I really wouldn't worry about it. The best you're going to do is stop your program from crashing due to a corrupt file, and at that point what can you really do anyway?"


Good point, the checks are there so I can figure out where the file is corrupted, (if it is) but when my map editor is finished I'll just take them out. My program already is slow (I have an old computer), but that might also be caused by the file reader checking for syntax, skipping blank lines, skiping comments and extracting comma separated values from strings. Yes, I think I'll take those checks out once my map editor is done.

Quote: "If you declared them in a function, it would be better if you were deleting and making these sprites in the game because it'd be the easiest way to find a free number, but it would also be harder to keep track of ."


I think I'll go with using a function. I won't be constantly creating and deleting media; only when a new map is loaded. I don't want to have a huge list of all the images and their numbers like my FPS mini-game, so I think a dynamic system is the way to go. I'm still concered about referencing them, though. The only way I can think of keeping track of sprites and images whose numbers are in no definite order is using an array to hold the numbers.
I already have serveral arrays, but I can't figure out how to use the stack/quene commands. Does anyone know a good tutorial on them?

Until I know how to use them I must make the arrays as a constant size, usually using more memory than is needed and slowing it down.

Thanks for your help!
Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 22nd Aug 2006 21:11 Edited at: 4th Sep 2006 02:26
[edit]
Sorry, somehow my last post got posted twice. I deleted the second one.
Cave Man
18
Years of Service
User Offline
Joined: 22nd Aug 2006
Location: North Carolina, US
Posted: 25th Aug 2006 16:10
Quote: "
I already have serveral arrays, but I can\'t figure out how to use the stack/quene commands. Does anyone know a good tutorial on them?
"



You can add to the end of an array with the ARRAY INSERT AT BOTTOM command.


If you want to add more than one spaces then use the extra parameter.



you can also remove using "ARRAY REMOVE ELEMENT array name, index".


You can't use those with multi-dimensional arrays, so i think you should read the width and height, then undim, then dim again with the width and height.

lol
Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 26th Aug 2006 20:30 Edited at: 22nd Jun 2007 21:13
Thanks, I think I understand how to add and remove elements from arrays now.

I'm confused about undim though, because in every other programming language I've used, global arrays can't be destroyed, and I've read that all arrays in Dark Basic are global. Does this mean that I can dim an array in one function and undim it in
another?

[edit]
Never mind, I think I figured it out.

You never really know a person until you look at their google autocomplete entries.

Login to post a reply

Server time is: 2024-11-27 10:00:42
Your offset time is: 2024-11-27 10:00:42