Probably an elementary error

BlitzMax Forums/BlitzMax Beginners Area/Probably an elementary error

Xerra(Posted 2010) [#1]
I'm sure there's a logical reason why this wont work when I use strict yet compiles fine if I don't. However I can't work it out and I hate programming something without being tidy. Anyone able to answer this and perhaps suggest what I should be doing?

Global EnemyList:TList = CreateList() ' list of aliens.
Global EnemyImage:TImage[4+1]
EnemyImage(1)=LoadAnimImage("images\Alien.bmp",16,8,0,1)
EnemyImage(2)=LoadAnimImage("images\Alien.bmp",16,8,1,1)
EnemyImage(3)=LoadAnimImage("images\Alien.bmp",16,8,2,1)
EnemyImage(4)=LoadAnimImage("images\Alien.bmp",16,8,3,1)

The error message says: Expression of type "brl.max2d.TImage Array" cannot be invoked.

Thanks.


Volker(Posted 2010) [#2]
Use
EnemyImage[1] = LoadAnimImage("images\Alien.bmp", 16, 8, 0, 1)
instead.
The brackets are wrong.
Since Blitz without strict mode creates variables on the fly, I'm
too interested, what is getting created with 'EnemyImage(1)'.


Xerra(Posted 2010) [#3]
Yup, that's spot on. I was using the wrong bracket. That's a code snippet I took out of another bit of code i wrote years ago so it's a bit bodgy anyway but did what it was meant to so I'm as confused as you are why it worked outside of strict mode.

Thanks for your help on that one.


Czar Flavius(Posted 2010) [#4]
Remember arrays now start at 0, not 1. You should create it with size 4, not 5.


ima747(Posted 2010) [#5]
Here's a little cleanup with comments for the record
Global EnemyImage:TImage[4] ' array with 4 spaces

'Arrays start at 0, and use brackets. 0 through 3 is 4 spaces
EnemyImage[0] = LoadAnimImage("images\Alien.bmp",16,8,3,1)
EnemyImage[1] = LoadAnimImage("images\Alien.bmp",16,8,0,1)
EnemyImage[2] = LoadAnimImage("images\Alien.bmp",16,8,1,1)
EnemyImage[3] = LoadAnimImage("images\Alien.bmp",16,8,2,1)