TNT Basic Forums > Programming Q&A
Array not working...
< Last Thread     Next Thread >
Thread        Post A Reply

03-13-2002 00:54

Posted by:

Click Here to Email bgroves   Find more posts by bgroves

Here's a piece of my code:

if shot<totalshot
end if

And I get:

Error: nx[shot]=xpos
Array index out of bounds.

When shot=0, totalshot=10, and nx[10]. Any thoughts?

03-13-2002 13:28

Posted by:

Find more posts by MiniMe

I think that arreys have to be one more becouse of the zero or something... So you should have: totalshot=11

03-13-2002 13:39

Posted by:
John Treece-Birch

Find more posts by John Treece-Birch


I'm not sure what the problem is because I can't see the loop in the piece of code you posted but it will probably be the fact that if you define a 10 element array it only gives you elements 0 to 9. It still gives you 10 elements exactly like you asked for but you don't actually get element number 10.

Hope this helps,

03-13-2002 18:35

Posted by:
Charles Robinson

Click Here to Email Charles Robinson   Find more posts by Charles Robinson

I think it should be

if shot<totalshot-1

because it counts up from 0 instead of 1.

03-20-2002 18:34

Posted by:
James Rhodes

Click Here to Email James Rhodes   Find more posts by James Rhodes

array out of bounds

Simple rule to remember... The numbering of the elements in the array ALWAYS begin with 0. So if you have the following:

exampleArray[100] ... a 100-element array

The numbering of the elements within the array (or another word for array is table) is from 0 to 99. If you tried to access element 100, you would get an out of bounds error simply because there are not 101 elements in the array.

In general, array elements are numbered n-1(while the array has n elements).

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.