need help with types!
BlitzMax Forums/BlitzMax Programming/need help with types!
| ||
| Global nofgi=3'number of icons to display Global img:TImage Function SetupMainWindow() Local x:Int For x=1 To nofgi Local gi:gameicon = New gameicon gi.iconnum=gi.iconnum+1 img:TImage=LoadImage("icon"+gi.iconnum+".png") Next End Function Function UpdateMainWindow() If KeyHit(2) Then nofgi=nofgi+1 Local For gi:gameicon = EachIn gameicon If img Then DrawImage img,0,111 Next End Function |
| ||
At first you have to define the type and its fields:Type GameIcon
Field img:Timage, IconNum%
End TypeThen you have to understand that all elements of the type are individual variables. so this will not work: Local gi:gameicon = New gameicon gi.iconnum=gi.iconnum+1 Always when you create a new GameIcon its IconNum is 0 so you better would do it like this: gi.IconNum=x You keep the 3 images independent they have to be a field of the type variable: gi.img=LoadImage("icon"+gi.iconnum+".png") there is a difference betwenn BlitzBasic and BlitzMax. In BlitzMax you need to create a list to store each member of the type: Global GiList:TList= New TList
.....
For x=1 To nofgi
Local gi:GameIcon = New GameIcon
GiList.Addlast gi
In your last function I do not know exactly, what you planned to do. Do you want to display one of the images, depending on KeyHit()? In BlitzMAX KeyHit() uses CONSTANTS to define the key If KeyHit(KEY_2) you forgot to reset nofgi back to 1. In your code it would become 4: If KeyHit(KEY_2) Then nofgi=nofgi+1 If nofgi>3 Then nofgi=1 Here is the complete corrected code: SuperStrict
Type GameIcon
Field Img:TImage, IconNum:Int
End Type
Global nofgi:Int=3'number of icons to display
Global GiList:TList= New TList
Function SetupMainWindow()
For Local x:Int=1 To nofgi
Local gi:GameIcon = New GameIcon
gi.IconNum=gi.IconNum+1
gi.Img:TImage=LoadImage("icon"+gi.IconNum+".png")
Next
End Function
Function UpdateMainWindow()
If KeyHit(KEY_2) Then nofgi=nofgi+1
If nofgi>3 Then nofgi=1
For Local gi:GameIcon = EachIn GiList
If gi.Img Then DrawImage gi.Img,0,111
Next
End Function
|