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 / Vespers Data Tutorial beginner to intermediate

Author
Message
Vesper103
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Beloit WI
Posted: 25th Feb 2008 17:22 Edited at: 28th Feb 2008 04:26
The data command is immensly usefuly in certain methods of tileing a map. Without it you would have to use an array and manually set each sprite for each tile, as you can guess even a small 10x10 map would be 100 lines of code, for just one map! data can make this go much faster than that, as you can "draw" the map in the editor as long as you know your sprite frames. Allow me to explain

lets say for simplicity sake you have a simple 2x1 tileset. One tile for grass, and one for a wall.

one method for setting up your map is as follows(assumiong frame 1 is grass and frame 2 is wall)





as you can see that method would take quite some time as you would have to define 100 array values for each map you made. there has to be an easier way right?

...
..
...
RIGHT!

using the "data" "read" commands you can literally draw the map, the load it as sprite data. heres the syntax

data data_1,data_2,data_3,ect.....

with this method you would draw the 10 by 10 map you want as follows




now thats much simpler right? you can actually see the map where 2 = walls and 1 = grass. But how do you read this value?

using the read command!

read var

this allows you to read the values from left to right top to bottom of the data . and store it to a variable.
heres an example of the use of both:



This would create a data set holding the numbers 1-8. it then sets all variable places to hold each data in order. then it prints the data to screen. Resulting in:

Quote: "
1
2
3
4
5
6
7
8
"


but how does this allow you to make a game? think about it. if you draw the map using a data set. then load that into a array(data_set_width*data_set_height). Then you just created a grid of game data that holds the sprite value. Simply draw that to the scrren using whatever method you prefer and Voila! much faster map makeing!
~Vesper103

[Challange]
Create a sprite sheet of a 5x5 black and 5x5 white tile. then using data & read. draw a picture on the screen using those two tiles.

(hint you will need to create a loop to create as many sprites as you have tiles)

post your code in this thread

[edit]
Dont put the variable to be read to in parenthsis, that will cause your code to not run. Also below this i will add a full program to draw a basic 5x5 map using data read and the 2x1 spriteset "tileset.bmp"



Your signature has been erased by a mod - please limit your signature to 600x120
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 25th Feb 2008 18:29 Edited at: 25th Feb 2008 18:30
not gonna post my code

Nicely put together.

Vesper103
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Beloit WI
Posted: 25th Feb 2008 19:34
Thank you, i have to admit i didnt listen to TDK's tutorial making tutorial (sorry TDK) as I am a noob in all respects but i think i got a really solid grasp on the concept and its implimentation at least in one area. i had to figure out tiling without any help so basically i wanna make the tutorials that are missing because ive had some trouble getting to where I am(even tho im barely scraping the surface)

Your signature has been erased by a mod - please limit your signature to 600x120
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 25th Feb 2008 19:47 Edited at: 25th Feb 2008 19:49
That was quick!

You joined 4 days ago, only posted asking how to use data statements four days later and on the same day you post a tutorial using them!

It's better for a user to have years of experience with DB rather than hours before they start writing tutorials.

It's better to know the subject inside out so that a) you don't go misleading other newcomers who assume you know what you are talking about and b) make silly errors in both the text and code snippets.

Your 'tutorial' isn't actually that bad, but you should correct the errors in it - in particular the fact that in a tutorial, any code snippets should actually run! Your second one doesn't.

Check out number 15 here:

http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

[Edit] Your post appeared while I was writing this, so I see you already know about the guide I linked to!

TDK_Man

Vesper103
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Beloit WI
Posted: 25th Feb 2008 19:50
wow okay thanks, ill edit bot my codes into fully, runnable programs. Thanks for not locking it btw, I know it was rather quick but i truely do feel i have a good grip on how data and read work and they're applications. and I didnt see it in any other tutorials so i figured id share as it was kinda tricky for me to figure out (i slept 0 hours last night im at school right now running off of 1 pot of coffee and 2 monster energy drinks) so i could learn that an memblocks.

Your signature has been erased by a mod - please limit your signature to 600x120
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 25th Feb 2008 20:05 Edited at: 25th Feb 2008 20:06

Your Top piece of code is Written in dbpro..Right?
We are in The Classic Forums.
Plese Refrain From Using examples Written in DbPro.


Anyway This is a pretty good tut.
Scince I dont use the data command a lot, I've learned a thing or two...
Vesper103
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Beloit WI
Posted: 25th Feb 2008 20:09
actually i meant to put in in the newcomers thread i dont know how it ended up here. if someoen could move it that would be great and im glad you learned something. Im editing it a little as TDK is right i did do a few things wrong.

Your signature has been erased by a mod - please limit your signature to 600x120
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 25th Feb 2008 20:33 Edited at: 27th Feb 2008 00:18
I'll move this to the DBP newcomers board.

Two things:

1. Data statements should really be at the end of the program and you should use Restore before reading data items to ensure that the data list pointer is correctly set.

2. Adding a Rem at the end of a line technically creates a multiple statement line. As such, there should be a colon ( : ) to separate them. It looks like DBPro allows it without using one, but DBC doesn't - that's why your code snippet failed to run in DBC.

[Edit] Damn smileys!

TDK_Man

Vesper103
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Beloit WI
Posted: 26th Feb 2008 21:17
ohhhhhhhh okay, double thanks tdk it is much appreciated. Dont worry im not done with this tutorial yet. and good to know about that REM stuff.

Your signature has been erased by a mod - please limit your signature to 600x120
Paul08
16
Years of Service
User Offline
Joined: 20th Feb 2008
Location: Oxford, UK
Posted: 26th Feb 2008 21:33
only one code problem and that was here:
load image "tileset.bmp",filenumberhere

could you maybe update the tutorial so we can see how to distinguish between a 1 or 2 in the dataset? im not too sure but to me it looked as though it would only ever display the one image in all 25 tiles?
but the '2' should indicate a different tile?
Vesper103
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Beloit WI
Posted: 26th Feb 2008 21:37
you would set the data number to a frame number 2 indiceates a wall in the 2x1 tileset with 1 being grass and 2 being wall. I left that out because that is mostly user created and changed to his own purposes. and i didnt want readers to belive 2 was some magic number or something (like boolean 1/0)

but i do like this


that would set the frame to whatever is contained in the data. automatically setting the tile to be shown to the data set. hope that wasent too confusing

Your signature has been erased by a mod - please limit your signature to 600x120

Login to post a reply

Server time is: 2024-11-25 07:43:00
Your offset time is: 2024-11-25 07:43:00