Nicholas369
Nicholas369

Reputation: 47

App Game Kit BASIC language array out of bound, array empty

I am currently using App Game Kit and trying to learn the BASIC language at the same time. I have this error that have happened in this Function, its in this line:

The error show:

Array index out of bounds, Index: 0, Array Length: <Empty> in GameRenderer.agc at line 14



holeSprites[I] = holeSprite

And this is the file that contains the line:

global DIM holeSprites[5]

Function RenderHole()
	holeImage = LoadImage ( "Orb.png" )

	FOR X = 1 to 2
		FOR Y = 1 to 2	
			I = 0
			holeSprite = CreateSprite ( holeImage )
			SetSpriteSize(holeSprite, 70, 100)
			SetSpritePosition ( holeSprite, 100 * X, 170 * Y)
			holeSprites[I] = holeSprite
			inc I
		NEXT Y
	NEXT X	
EndFunction	

----------------------------------------------------------------------
I need help in learning BASIC programming language thanks!

Upvotes: 0

Views: 124

Answers (1)

micheg79
micheg79

Reputation: 51

In some basic the lowest array index is 1. Then you should put the I variable outside the second for..next otherwise you reset the value on each iteration. The size of holeSprites can be 4, you are assigning before inc and the two "for..next" are iterating 4 times.

Try:

global DIM holeSprites[4]

Function RenderHole()
    holeImage = LoadImage ( "Orb.png" )
    I = 1
    FOR X = 1 to 2
        FOR Y = 1 to 2  
            holeSprite = CreateSprite ( holeImage )
            SetSpriteSize(holeSprite, 70, 100)
            SetSpritePosition ( holeSprite, 100 * X, 170 * Y)
            holeSprites[I] = holeSprite
            inc I
        NEXT Y
    NEXT X  
EndFunction 

Upvotes: 1

Related Questions