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 / How to use hundreds of thousands of Data Commands? Is it using Restore?

Author
Message
Irojo
17
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 10th Jul 2008 04:51
I want to be able to make hundreds of images like so:




But I dont' know how to keep on using the data command, if I went
past 'z'

i.g.

read a
read b
etc...
read z
???


Thanks for your help. If this helps anymore, I plan on using this for sprites. As in, you press spacebar for your jump, and a new sprite appears. Thanks. -Irojo

I urge you to watch the film "Who killed the electric car". Support electric cars! Did you know their used to be more electric cars then gassoline cars?
Sinani201
18
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 10th Jul 2008 05:53
In excel, after z is aa, ab, ac, ad, etc. and then aaa, aab, aac,and so on.


BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 10th Jul 2008 10:00
You are using restore incorrectly. Restore simply resets the location to the first data statement in the code. When coupled with a label name, it goes to the first data statement within the label. So, everytime you use RESTORE pic1 you simply make it do the same line over and over. If you remove all of the extra ones, it should let it continue reading past the first line.

I know you know why you are doing it this way, but I must ask, if you are using it for sprites...why not just use sprites?

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 10th Jul 2008 10:14 Edited at: 10th Jul 2008 10:17
@Irojo

You can use any named variable you want to read in data from a data statement



And you only have to use RESOTRE if you want to reset the data and read it from the beginning of the statements or where you've placed a lable. Here's a variation of your program without all the individual variables for the data lines. I use one variable to read back all of the data:



But as you get more experienced in programming, you'll find other means to store your data - like in files for example, or in memory as arrays or memblocks.

Here's an example that stores the data in an array. Though this example isn't necessarily more efficient than the last (depends on what you do with the array), it will allow you to reference and use any of the data at any time in the program by just identifying the index of the array:



Enjoy your day.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 10th Jul 2008 16:15 Edited at: 10th Jul 2008 16:18
Just to expand on what Latch correctly said...

If you don't use Restore, Read will read the very first Data item and set a pointer to the next data item. The next read will read the data item currently being pointed to then set the pointer to the next item and so on.

This will eventually read in ALL of the data items and when the last one has been read in, the next Read will cause an error. This is where Restore comes in.

What restore does is allow you to set the pointer to any given item in the data list and does this by using a label. For example:



Once all the data has been read in the data pointer will be invalid as there are no data items left to be read in. Note that the labels are completely ignored when reading.

So, to read them ALL back in again you would use:

Restore DogData

This sets the pointer back to the very first data item after the label.

But, a more useful option is to set the pointer to a specific set of data. So, to read the data in for just the pig you would use:

Restore PigData

..then read in the 9 data items.

Obviously you can do this with all of the data sets by restoring the required data set with the correct label. You don't have to read all the animal's data each time if you only want one of them.

But, as Latch said, if you have a lot of data then external files for each data set makes much more sense.

TDK_Man

Irojo
17
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 10th Jul 2008 19:24
If I understand it right TDK, restore is like gosub for data, and the way it works is like:


gosub PigData

PigData:
Data 55,5,12,62,35,27,88,31,16
return

?


@ Latch

Thanks. That makes since.

@ Sinani
Thank you.

I urge you to watch the film "Who killed the electric car". Support electric cars! Did you know their used to be more electric cars then gassoline cars?
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 10th Jul 2008 20:27
This will help you:

Image to DB code converter, if you don`t have a better program. You can simply load an image into this program, it will produce code for you, which you can simply copy into your program, and you don`t even need to write anything!

Irojo
17
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 10th Jul 2008 20:29
Thanks. Those programs that convert things to code are so cool.

I urge you to watch the film "Who killed the electric car". Support electric cars! Did you know their used to be more electric cars then gassoline cars?

Login to post a reply

Server time is: 2025-06-07 07:09:59
Your offset time is: 2025-06-07 07:09:59