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 / multiple "data" commands

Author
Message
NachoMan
22
Years of Service
User Offline
Joined: 14th Apr 2003
Location: United Kingdom
Posted: 9th May 2003 21:53
I have seen in a lot of code things lik
data 1,4,2,6,3....
data 2,6,3,7,2....
surely once you introduce another data command it runs over the original list and you cannot read it again. If not, how would you read multiple data commands?

data 1,2,3,4,5
data 5,4,3,2,1

?????
Nick
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 9th May 2003 23:31
No, it reads every piece of data.

for example, if you'd use something like

data 1,2,3,4
data 5,6,7,8

and read it, you'd get 1,2,3,4,5,6,7,8 as values. Experiment with it, maybe try out this code.

dim data(10)
for i=0 to 9
read data(i)
print data(i)
next i

data 1,2,3,4,5
data 6,7,8,9,10

Whatever I did I didn't do it!
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 9th May 2003 23:49 Edited at: 9th May 2003 23:52
then if you want to read some part of the data over again you do this

for i=0 to 3
read x(i)
next i
restore half_of_data
for i=0 to 1
read y(i)
next i
data 123,456
:half_of_data
data 789,101

the first time the code will read all four numbers, and the second time just the numbers in the data statement after the label half_of_data, the restore command resets the reading to the position indicated by the label name in restore,so..
x(0)=123
x(1)=456
x(2)=789
x(3)=101
and
y(0)=789
y(1)=101

hope thats some help.

Mentor.

Oh! and if you just want to read the data over again from the start then just use the instruction RESTORE on it`s own.

NachoMan
22
Years of Service
User Offline
Joined: 14th Apr 2003
Location: United Kingdom
Posted: 10th May 2003 00:04
cool! thnx guys! i can reduce my code by loads now!
Nick
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 10th May 2003 01:26
No prob

Cheers,
Kentaree

Whatever I did I didn't do it!

Login to post a reply

Server time is: 2025-05-17 15:52:32
Your offset time is: 2025-05-17 15:52:32