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.

DarkBASIC Discussion / Data Command?

Author
Message
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 24th Mar 2009 19:41
Ok i have never used the data command.

not sure what it does. any help? lol the dbc help isn't that great in my oppinion

New Site! Check it out \/
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 24th Mar 2009 22:00
What you do is you use the DATA command to define some data, i.e.

REM Some Data Numbers
DATA 1
DATA 2
DATA 3
DATA 5


Then, you use the READ command to see what you have, i.e.

REM Some Data Numbers
DATA 1
DATA 2
DATA 3
DATA 5

REM The Array I'm going to fill with the numbers
DIM reads(4)

REM Read the data
FOR i = 1 to 4
READ int
reads(i) = int
PRINT int
NEXT i


This little snippet will first define some data, then make an array to put it in, and finally read that data and put it into the array.

You can also have multiple bits of information on each DATA command. This snippet has to do with contact information:

REM Contacts
DATA "Bob","Jones","12345 Main St.",25
DATA "Jane","Doe","7645 Side Blvd.",34

REM Contact Array
DIM contacts$(2,4)

REM Read the data and put it in the array
FOR i = 1 to 2
READ Name$,Last$,Address$,Age
contacts$(i,1) = Name$
contacts$(i,2) = Last$
contacts$(i,3) = Address$
contacts$(i,4) = STR$(Age)
NEXT i


I think that you can figure that one out for yourself.

Finally, you can use the RESTORE command to go to a label to read from data from there, rather than from the first DATA command. i.e.

REM Aliens
Aliens:
DATA "Bob",3
DATA "Joesnicker",7
DATA "Blargfen",1

REM Monsters
Monsters:
DATA "Freddy",3
DATA "Jiminy",9
DATA "Sam",11

REM Read the data
RESTORE Monsters
PRINT "MONSTERS"
FOR i = 1 to 3
READ Name$,Attack
PRINT "Name: "+name$+". Attack: "+attack
NEXT i

RESTORE Aliens
PRINT "ALIENS"
FOR i = 1 to 3
READ Name$,Attack
PRINT "Name: "+Name$+". Attack: "+attack
NEXT i


The DATA command can be used for information such as stats or levels, because you can easily compact it into easy blocks, then go to the one you need, as an alternate to opening separate files.

Hope that helped!

~QJ
That's what they WANT you to think...
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 24th Mar 2009 23:39
yes it did thanks!

i had seen them used but had never worked with em.

New Site! Check it out \/
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 24th Mar 2009 23:46
I really haven't used them myself, but I'm sure that they can come in handy!

~QJ
That's what they WANT you to think...
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 24th Mar 2009 23:51 Edited at: 24th Mar 2009 23:52
yup! figure better to learn now then after i already did something the really long way and need to completely rebuild my code

New Site! Check it out \/
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 25th Mar 2009 00:19
the only time ive ever had to use i is in my current poker game, and even then i really didnt need it but i had some bug and i needed an alternate way to do something so i used it

so really its not a widely used command, but it is a quick way to edit data in games
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 25th Mar 2009 00:46
The only time I could think of a convenient use for the data command is to read all of the data into arrays at the beginning of the program, then just use arrays. But it would help save some coding time. Still though, I rarely use it myself.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 25th Mar 2009 00:58
Thanks for all the input.


I had only seen it used a couple of times anyway lol.

New Site! Check it out \/
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 25th Mar 2009 02:17
In ancient times, one might use data statements to write machine code into memory through BASIC. You'd POKE your assembly code directly into memory as you read the DATA. This was a way of writing "fast" working programs that could still exist even if you loaded in a new basic program (unlike DBC's interpreter, many machines had a built in interpreter that allowed you to load in additional or suplimental BASIC code).

If you want your program self contained and don't want to use external files to store things, you could use data statments - say to design a matrix, or for some small simple graphics, or to hold the mapping of your levels.

In one of the last few DBC challenges, I stored an encrypted version of all the words that would be used in a hangman game in data statments.

Actually, if you had a small sized DLL and you didn't want anyone to use it outside of your program but need to distribute it for your program to work, you could break it down into bytes or DWORDS and store those in data statements. Then when your program is launched, you could write the data to a file, load the file in as a dll, then delete the file that was created by your program. The DLL would be loaded and ready to use, and when the user was done with your program, there wouldn't be any DLL there for them to mess with.

Enjoy your day.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 25th Mar 2009 02:40
interesting history lesson latch
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 25th Mar 2009 02:43
oh ok i see so that command is just kinda out dated?


that is a good idea latch! (the dll thing)

New Site! Check it out \/

Login to post a reply

Server time is: 2025-05-16 07:33:34
Your offset time is: 2025-05-16 07:33:34