forums

TNT Basic Forums > Programming Q&A
data statements
< Last Thread     Next Thread >
Author
Thread        Post A Reply

02-14-2004 21:29

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

i've written an initialization procedure that reads from data statements:

procedure init()
int i
read nMobileParts
for i = 0 to (nMobileParts - 1) step 1
read partMx, partMy, partRadius, partAngle
read partSpeed, partPattern, partType
next i
end proc

what i want to know is how do i wright the data statements when i'm filling out arrays whose size is determined by reading a data statement. i've never really done this before and i'm kinda confused.

02-14-2004 23:55

Posted by:
-wyvern

Location:
Bedroom

Find more posts by -wyvern

Simple - First, create a variable for the size of the array, and read a statement into it. Then define your array using this value, and read the other values into it in a loop. Do some experiments, you'll soon get used to it. Have fun.

02-15-2004 00:21

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

here is my procedure complete with data statements.

procedure init()
int i
read nMobileParts
for i = 0 to (nMobileParts - 1) step 1
read partMx{i}, partMy{i}, partRadius{i}, partAngle{i}
read partSpeed{i}, partPattern{i}, partType{i}
next i
end proc

data 5, 320, 240, 5, 90, 1, 0, 0, 320, 240, 10, 95, 2, 0, 0
data 320, 240, 15, 100, 3, 0, 0, 320, 240, 20, 105, 4, 0, 0
data 320, 240, 25, 110, 5, 0, 0


and here is the error i get.

*** Runtime exception caught ***
Line# : 31
Code : read nMobileParts
Error : Out of readable data.

according to this, there's a problem with the first read statement. now i'm real confused.

last time i posted this all of my arrays got cut off so now they're enclosed in curled braces.

02-15-2004 01:49

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Data statements are local, so procedures can only read data that is inside the procedure itself.

02-15-2004 03:07

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

i nearly replied with a snide comment, until i noticed i mistakenly put the end proc before the data statements. thanks for pointing that out.

02-15-2004 03:28

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

procedure init()
int i
read nMobileParts
for i = 0 to (nMobileParts - 1) step 1
read partMx{i}, partMy{i}, partRadius{i}, partAngle{i}
read partSpeed{i}, partPattern{i}, partType{i}
next i

data 5, 320, 240, 5, 90, 1, 0, 0, 320, 240, 10, 95, 2, 0, 0
data 320, 240, 15, 100, 3, 0, 0, 320, 240, 20, 105, 4, 0, 0
data 320, 240, 25, 110, 5, 0, 0
end proc

now my problem is when i read partMx{i}, which is 320, i get an array out of bounds error, as if it is trying to access element 320 of array partMx, instead of setting element i of array partMx to 320. i tried reading into normal variables and assigning them to the array and i still get the same error. i'm gonna do a little sniffing around, but this almost seems like a bug.

02-15-2004 03:38

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

quote:
what i want to know is how do i wright the data statements when i'm filling out arrays whose size is determined by reading a data statement. i've never really done this before and i'm kinda confused


Dimension the arrays using the "dim" command.

02-15-2004 03:51

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

could i be having such a problem because you can't dimensionize an array to a variable? the statement "dim partMx{i}" returns an invalid array dimension error. that doesn't make a lot of sense to me though.

02-15-2004 07:31

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

You should be dimensioning it to nMobileParts, not i. If you use i, the first thing your code tries to do is dimension it to 0.

02-15-2004 07:51

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

at the start of my game i declare all my arrays with the size nMobileParts, which at that time = 1. the for loop iterates from 0 to the size of the array - 1 so as to set up each piece of my game. at that point i'm no longer dimensioning the array, i should be accessing the ith element of the array. maybe i'm trying to access the arrays the wrong way, but that's the way it's described in the documentation. needless to say i'm getting pissed.

02-15-2004 08:17

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

well, what can i say? i'm a moron, perhaps?

after re-reading my previous post, i see that i clearly outlined - in my own words mind you - the reason why my shit wasn't working.

quote:
at the start of my game i declare all my arrays with the size nMobileParts, which at that time = 1.


eekaydee, i'm fairly certain now that your were trying to tell my this all along, so thanks. your good advice must of found a way of seeping into my subconscious in spite of all my best efforts to stop it.

on the bright side it looks badass when it's running.

02-15-2004 09:17

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

You're welcome. Glad I could help.

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.