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.

Newcomers AppGameKit Corner / I'm getting an index out of bounds. I just can't spot how. Can anyone help?

Author
Message
Imagination Engineer
4
Years of Service
User Offline
Joined: 30th May 2014
Playing: Street Fighter V
Posted: 12th Mar 2018 19:53 Edited at: 12th Mar 2018 19:56
Array index out of bounds, index: -1, Array Length 16 in main.agc at line 188

Imaginations' greatest gift is the knowledge you supply it.
blink0k
AGK Developer
5
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 12th Mar 2018 19:59
Missing constants.agc
Have you tried using the debugger?
Phaelax
DBPro Master
15
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 12th Mar 2018 19:59 Edited at: 12th Mar 2018 20:07
None of your NEXT statements have a variable. I would think that would cause an error.

Off hand, I can't see why anything would end up with an index of -1. Also, you have a lot of globals that I don't think need to be global, such as cubeDirection. You can easily make that a function parameter and pass it that way.

An option to figure this out would be to comment out sections of code and run it. Try to narrow down what piece of code is causing the error. Yes line 188 says it has the error but the problem could lie elsewhere and just cascade down to that spot.

I've corrected your code tag and indentation
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
puzzler2018
User Offline
Joined: 8th Oct 2017
Location:
Posted: 12th Mar 2018 20:06
Is there a reason why your setting up your rc as Cube




for y=0 to 13

If 64 units, shouldnt this be

for y=0 to 15

??
Imagination Engineer
4
Years of Service
User Offline
Joined: 30th May 2014
Playing: Street Fighter V
Posted: 12th Mar 2018 20:51
Ok, I've gone through the various suggestions you guys have posted. It still spits the error. Arggghh.

I've uploaded the entire archive which should compile so you can test.
Imaginations' greatest gift is the knowledge you supply it.

Attachments

Login to view attachments
puzzler2018
User Offline
Joined: 8th Oct 2017
Location:
Posted: 12th Mar 2018 21:02
It boms when you go left - cause not got any code to detect boundaries

Its returning a -1

So need to add boundary detection

Like

If X<0 then X=0
If Y<0 then Y=0
if X>width of grid then x=width of grid
if Y>height of grid then y=height of grid


puzzler2018
User Offline
Joined: 8th Oct 2017
Location:
Posted: 12th Mar 2018 21:07
Like this perhaps

Imagination Engineer
4
Years of Service
User Offline
Joined: 30th May 2014
Playing: Street Fighter V
Posted: 12th Mar 2018 21:25
Adding bounds checks fixes the error but now the issue is that the red cubes no longer correctly stop when they hit a grey cube.

Maybe I need to back away a little to refresh. I'll try tackling it again in a few minutes.

Imaginations' greatest gift is the knowledge you supply it.
puzzler2018
User Offline
Joined: 8th Oct 2017
Location:
Posted: 12th Mar 2018 21:28
I thought it looked a bit on the odd side with the player sprite flying off the screen and should be stopping when meets a wall

so,

Maybe could add a SpriteCollision system

thus

SpriteCollision(player, walls) = 1 then stop...


Welcome to world of programming

puzzler2018
User Offline
Joined: 8th Oct 2017
Location:
Posted: 12th Mar 2018 21:39
If I have got half hour spare tomorrow - ill quickly put something together for you then im back on Minecraft
GarBenjamin
1
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 14th Mar 2018 03:23 Edited at: 14th Mar 2018 03:25
I wasn't exactly sure what you wanted this to do but this makes the cubes move left and right checking for a tile that blocks their movement.
I tried to keep your structure the same.

TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)

Login to post a reply

Server time is: 2018-06-24 21:13:34
Your offset time is: 2018-06-24 21:13:34