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 Professional Discussion / Deleting elements from a array gives a array out of range error

Author
Message
Hayer
20
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 14th Jun 2010 04:04
First off, here is my source code - this is just a test.

I got a array that handles all the units and stuff like that, and there is no comments and blah blah - what im trying to say is;
sorry for a messy source code ;p




at line 204 to 209 i delete the array elements of the units which are dead, the problem is that this causes a "array out side of bounds" error.. And i can't seem to figure out which loop that causes this error, can anyone help?

( its 3'oclock at night here btw )

Keep it simple.
Questions? Mail me
Brendy boy
21
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 14th Jun 2010 04:51 Edited at: 14th Jun 2010 04:53
when you delete an array element all remaining elements after the deleted element get shifted by one element towards the begining of the array. So when you delete one element, the element at index array count(array name(0)) doesn't exist any more->thats why you are getting error.

change this:

to this:


Hayer
20
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 14th Jun 2010 12:24
seems to work, even thou' i dunno why? >_>

Keep it simple.
Questions? Mail me

Login to post a reply

Server time is: 2026-07-25 16:22:08
Your offset time is: 2026-07-25 16:22:08