News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Having issue with data and read syntax.

Started by LemonWizard, April 25, 2008, 03:08:27 AM

Previous topic - Next topic

LemonWizard

Hey. Having an issue with the read command.

How do I read data stored with the data command directly into an array, within a loop.

for example

PlayBASIC Code: [Select]
Dim map(10,10)

for tempx=1 to 10
for tempy=1 to 10
readdata map(tempx,tempy)
next
next

data 1,1,1,1,1,1,1,1,1,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,1,1,1,1,1,1,1,1,1



It returns an error saying "readdata expects to return a result"

What I want is to read that data into the array using my for temp loop... how do I accomplish this in playbasic?

(Later I'm going to be reading in the data from a file into an array)

kevin

#1
PlayBASIC Code: [Select]
for tempx=1 to 10
for tempy=1 to 10
map(tempx,tempy)=readdata()
next
next



Adaz

#2
Welcome in PB forums!

Let me advise 3 things:

- Read the help for syntax: Result = ReadData()
- Always indent the lines
- Don't use Next / Next! Always use Next <variable>

Your working code:
PlayBASIC Code: [Select]
Dim map(10,10)

for tempy=1 to 10
for tempx=1 to 10
map(tempx,tempy)=readdata()
next tempx
next tempy

data 1,1,1,1,1,1,1,1,1,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,1,1,1,1,1,1,1,1,1



Ádáz

Hungary