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

Author
Message
Takeshii
21
Years of Service
User Offline
Joined: 15th Feb 2004
Location:
Posted: 21st Oct 2005 20:30 Edited at: 21st Oct 2005 20:32
Hi, Im using a variable called max. then i have many global variables using it. in my main loop ( a do loop) when i try to incease max, its array accessed out of bounds...How can i increase max during my loop with out getting this error? because max determines how many enemies there are, and periodicly in my game, i want it to increase, thus theres more enemies.

Dark
<I>TDK I Love you...... And yes, you should be scared</I>
Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 21st Oct 2005 21:06
I know you'll not like it, but this is not possible...

It'll be better that you create an array big enough to store everything in the entire game.



Also a possibility (but causes a slowdown) is creating two arrays instantly to increase the max:


Just some quick examples. I know it's hard to get around it.

Immunity and Annihalation makes Immunihalation...
Takeshii
21
Years of Service
User Offline
Joined: 15th Feb 2004
Location:
Posted: 22nd Oct 2005 03:12 Edited at: 22nd Oct 2005 03:14
Bummer.

Thank you very much, this answered my question. I will give it a shot

Oh and shouldnt the enemies variable be above the dim...

Dark
<I>TDK I Love you...... And yes, you should be scared</I>
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 22nd Oct 2005 04:19
Quote: "Oh and shouldnt the enemies variable be above the dim"


No - that's only if you want to use the value of enemies in the DIM statement.

What Sven is saying is that you make the array HUGE then it won't matter how big Max gets during the game, it will never try to access an element of the array bigger than you dimensioned it.

And yes... I am scared. Very scared!

TDK_Man

Login to post a reply

Server time is: 2025-05-22 12:48:32
Your offset time is: 2025-05-22 12:48:32