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 / Array subscript out of bounds [DBP v7.61]

Author
Message
cyril
18
Years of Service
User Offline
Joined: 6th Aug 2007
Location: 7 miles away from big ben
Posted: 3rd Mar 2012 22:47 Edited at: 3rd Mar 2012 22:48
Just like the title states I currently have a problem of my bullet array falling out of bounds I've isolated the problem that when every I perform a check on a value inside an array using the IF statement my FireGun subroutine fails

Heres the section that the Array is set up, this section runs flawlessly:


And here is the subroutine that fails (Bold command is the one that is reported to have gone out of bounds:



I've attempted a Debug and the Debugger returns a "Broke from nested subroutine cannot return to CLI" Error. Am aware that the subroutine for the Playerinput and Bullet fired is the same, but could this cause the problem?
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 3rd Mar 2012 22:59 Edited at: 3rd Mar 2012 23:01
i would suggest you to do it other way:

1 way:
For i=1 to array count(bullets())-1 //use at 7.7 they fixed the -1 bug, so if u use 7.7 u wont need the -7 anymore.

2 way:

dim bullets() as bullet
total = 12
for a=0 to total
dim bullets(array count(bullets())+1) as bullet //creating the bullets at the first loop, thats the best way i guess.
b = array count(bullets())-1
bullets(b).bulletinuse = 0
next a


and to fix your problem:
if your array is dimmed till 12, you have to do:
for =0 to 12-1 //u have to start from 0 all the way to the top -1.

more 3d models .x/.obj and more foramts here:
[href]https://www.turbosquid.com/Search/Index.cfm?keyword=gogetax1&x=0&y=0[href]
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 3rd Mar 2012 23:00


What's that return doing at the very end?

Quote: "Am aware that the subroutine for the Playerinput and Bullet fired is the same, but could this cause the problem?"


Can you explain this a bit more, I don't understand... Are you using two return commands for one subroutine? Or two labels for one return?

TheComet

cyril
18
Years of Service
User Offline
Joined: 6th Aug 2007
Location: 7 miles away from big ben
Posted: 3rd Mar 2012 23:06 Edited at: 3rd Mar 2012 23:45
@Sergey K: I'll try that now and see what I get, I'll report back

@The Comet: I was a bit sloppy with my copying of the code, That is a part of the Create bullets subroutine:



Quote: "Can you explain this a bit more, I don't understand... Are you using two return commands for one subroutine? Or two labels for one return?"


The subroutines are nested.

Edit: Updating to 7.7 and adopting Sergey K's first approach has stop the error from coming up now. Noticed I missed out an Exit command, made the gun 12 times stronger than intended. Thanks guys

Login to post a reply

Server time is: 2026-07-10 15:30:38
Your offset time is: 2026-07-10 15:30:38