TYPES and ARRAYS

BlitzMax Forums/BlitzMax Beginners Area/TYPES and ARRAYS

Mr Biscuit(Posted 2015) [#1]
Hi to all, this is my first post after finally trying out blitzmax.
Im already having issues with TYPES that have an ARRAY assigned to them. Ive read through a few tutorials...erm..what?????
This is how I used to do it.
TYPE invader
x ; y ; speed
ENDTYPE
GLOBAL list[] as invader ; dim list[40]

xp=20;yp=20
for a=0 to 39
list[a].x=xp ; list[a]=yp
xp=xp+25
if xp is greater than ten in a row, drop down several pixels and reset xp to 20....etc
next

What is the Blitzmax translation to creating the ARRAY linked to a TYPE and filling it with values?

Many thanks


Derron(Posted 2015) [#2]
Type Invader
  Field x:int, y:int, speed:int
End Type

global invaderArray:Invader[40]

local xp:int = 20, yp:int = 20
For local a:int = 0 to 39
  invaderArray[a] = new Invader
  invaderArray[a].x = xp
  invaderArray[a].y = yp
  xp :+ 25
Next



bye
Ron


Mr Biscuit(Posted 2015) [#3]
Thanks Ron!


Mr Biscuit(Posted 2015) [#4]
Ive added an object called- IMAGE to the Type. This dictates which GFX image is keyed to each part of the array. Before I did this I simply used: DRAWIMGAE hawk,invaderArray[a].x,invaderArray[a],y

Im loading the GFX this way, Global hawk:TImage ; hawk=LoadImage("GFX/hawk1.png",-1)

And then tried assigning it to the ARRAY via: invaderArray[a].im = hawk

This brought up an error message...doh.

Unable to convert from TImage to INT.

I understand whats going on but need help in implementing ,,,[a].im into the DRAWIMAGE command.

Thanks for your patience.

Mark


Derron(Posted 2015) [#5]
What type is "field im"?

It should be "field im:Timage"


Bye
Ron


Mr Biscuit(Posted 2015) [#6]
thanks


Mr Biscuit(Posted 2015) [#7]
I am actually alot brighter than I sound. :)

Blitzmax is vastly superior to my old language: GLBasic. And to be quite honest, I`m very excited by what Blitz has to offer.