I'm experimenting with arrays and array collisions
what is happening is I will get a error at line 125
stating :"array index out of bounds , index:6, array length:5 in main.agc line 125
sometime I will run it again and everything works fine
then the next time it will throw up a error but not always the same index# or array length#
I'm at my wits end....any help would be greatly appreciated.
line 125 is in the function collisions()
// Project: me_clowns_arrays
// Created: 2017-12-29
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "me_clowns_arrays" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
type clownType
sprite as integer
speed as integer
x as integer
y as integer
direction as integer
endtype
type scarytype
sprite as integer
speed as integer
x as integer
y as integer
state as integer
endtype
image = LoadImage ( "clown.png" )
// create sprites for each clown face
for i = 1 to clown.length
clown[i].x=random(1,500)
clown[i].y=random(25,700)
clown[i].speed=random(1,5)
clown [ i ].sprite = CreateSprite ( image )
SetSpriteScale(clown[i].sprite, .2,.2)
SetSpriteVisible (clown[i].sprite,1)
SetSpritePosition(clown[i].sprite,clown[i].x,clown[i].y)
next i
image = LoadImage ( "scary.png" )
// create scary faces
for i = 1 to scary.length
scary[i].x= random(550,1020)
scary[i].y= random(25,700)
scary[i].speed=random(1,5)
scary [ i ].sprite = CreateSprite ( image )
SetSpriteScale(scary[i].sprite,.2,.2)
SetSpriteVisible (scary[i].sprite,1)
SetSpritePosition(scary[i].sprite,scary[i].x,scary[i].y)
next i
global clown as clownType[10]
global scary as scarytype[10]
do
moveclown()
movescary()
collisions()
Print( ScreenFPS() )
print("Clowns:")
print(clown.length)
print("")
print("scary faces:")
print(scary.length)
Sync()
loop
function moveclown()
for i = 1 to clown.length
x = GetSpriteX ( clown [ i ].sprite )
y = GetSpriteY ( clown [ i ].sprite )
y = y + clown[i].speed
SetSpritePosition ( clown [ i ].sprite, x, y )
if getspritey(clown[i].sprite)>700
SetSpritePosition(clown[i].sprite,random(1,500),0)
endif
next i
endfunction
function movescary()
for z = 1 to scary.length
x = GetSpriteX ( scary [ z ].sprite )
y = GetSpriteY ( scary [ z ].sprite )
x = x - scary[z].speed
SetSpritePosition ( scary [ z ].sprite, x, y )
if getspritex(scary[z].sprite)<2
SetSpritePosition(scary[z].sprite,1020,random(1,700))
endif
next z
endfunction
function collisions()
for c = 1 to clown.length
for cc=1 to scary.length
if GetSpriteCollision(clown[c].sprite,scary[cc].sprite)=1////// This is line 125 ////
SetSpriteVisible(scary[cc].sprite,0)
setspritevisible(clown[c].sprite,0)
clown.remove(c)
scary.remove(cc)
//deletesprite(scary[cc].sprite)
//deletesprite(clown[c].sprite)
endif
next cc
next c
endfunction