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 / Array accessed out of bounds? What does that mean?

Author
Message
dab
20
Years of Service
User Offline
Joined: 22nd Sep 2004
Location: Your Temp Folder!
Posted: 29th Jul 2005 16:46
What does array accessed out of bounds. For some reason it says that everytime I try to make it equal to the y point in the screen.

if you need code just ask but what I am doing is this:



------------------------
Visit my website of Games!
http://dabip.stonerocket.net
BatVink
Moderator
22
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 29th Jul 2005 17:19
If an array has 10 elements, and you try to access element 11, you will get this message.

ARRAY COUNT() will tell you how many elements you have, if you have lost track.

Metrion
19
Years of Service
User Offline
Joined: 8th Jul 2005
Location: In the darkest cave
Posted: 29th Jul 2005 17:45
Another thing is that if you access

array(0)

this is a common mistake.

If practice makes perfect and nobody is perfect, then why practice?
dab
20
Years of Service
User Offline
Joined: 22nd Sep 2004
Location: Your Temp Folder!
Posted: 30th Jul 2005 03:07 Edited at: 30th Jul 2005 03:18
Well, I don't see what could be the problem. It couldn't be the array(0) thing but I'm going to check. And an element is the thing like this:
array(1,2,3,4,5,6,7,8,9,10,11)
right? IF so then thats not what the problem is.

edit: Uhh here's the source:
Also, the bullets (which is what I'm having trouble with) isn't quite finished with. I just ran into this error and couldn't get rid of it.

So far though, thanks for your help!

------------------------
Visit my website of Games!
http://dabip.stonerocket.net
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 30th Jul 2005 08:36
Accessing element 0 of an array is not a common mistake - it's there, so you can use it!

If you need an array to hold 4 values, you can use

DIM Arrayname(3)

Although arrays can be real or integer, element variables should always be integers.

y2#(numdot)=y#
y2(numdot)=y

are both OK, but

y2(numdot#)=y

is not.

In your code, you use

nume=1
dim y2(nume)=y

This means your array size is only 2 (elements 0 and 1). Once Nume gets to 2 then your error occurs because you told DB you only wanted an array to store two values.

What you need to do is DIMension the array to the biggest size you will need.

Try with

DIM y2(100)

or more if you know Nume is going to get bigger.

TDK_Man
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 30th Jul 2005 08:42
Oops - just noticed another problem...

You have

for stars = 1 to 300
dim starx(stars)
dim stary(stars)
next stars

this is wrong. What you are doing here is dimensioning both arrays 300 times - the first time with 1, then 2, then 3 and so on!

All you need is:

Dim starx(300)
Dim stary(300)

TDK_Man
blanky
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: ./
Posted: 30th Jul 2005 20:09
Yeah, what TDKMan said - You just declared your arrays 300 times over

Also, you CAN use element 0.

Syntax Error - Learn to type, you fool!
dab
20
Years of Service
User Offline
Joined: 22nd Sep 2004
Location: Your Temp Folder!
Posted: 30th Jul 2005 21:22
Oh OKay!! Thanks. I get it. Thank You!!

------------------------
Visit my website of Games!
http://dabip.stonerocket.net
blanky
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: ./
Posted: 30th Jul 2005 23:23
Yay!

[Insert extremely witty comment here]

Login to post a reply

Server time is: 2025-05-22 13:48:26
Your offset time is: 2025-05-22 13:48:26