types not working could use help!
BlitzMax Forums/BlitzMax Programming/types not working could use help!
| ||
please someone help, please correct code using bmx ng x64 win32 Import MaxGui.Drivers Graphics 800,600 Type gameicon Field img:TImage,num:Int End Type Global GiList:TList= New TList Local x:Int For x:Int=1 To 2 Local gi:GameIcon = New GameIcon gi.Num=gi.Num+1 gi.img:TImage=LoadImage("icon"+gi.Num+".png") Next While Not KeyDown(1) Cls Select WaitEvent() Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE End End Select For Local gi:GameIcon = EachIn GiList DrawImage gi.Img,0,0 Next Flip Wend EndGraphics End |
| ||
One of my main problem with blitzmax before. You just need to read through the manuals and other posted examples. Honestly, I'm not that familiar on how to manage BMX types yet, whereas in B3D it does it for you automatically like arrays and without the lists thing. Saying 'it is not working' is not the right title or word, please! |
| ||
@Caton: Look at the declaration of your type "gameicon" and then look at the definition "Local gi:GameIcon = New GameIcon"... Maybe it could be case sensitive. ;-) |
| ||
I just compiled it and it advised me of a duplicate identifier, try changing this:For Local gi:GameIcon = EachIn GiList DrawImage gi.Img,0,0 Next To this: For gi:GameIcon = EachIn GiList DrawImage gi.Img,0,0 Next The latter compiled without the error. |
| ||
I nerver did have compile errors. if I don't use For Local gi:GameIcon = EachIn GiList it will have a error. I try runing program but nothing draws. It's acting like it nerver created a new type. |
| ||
This is a problem of scope. You are declaring variable 'gi', of type 'GameIcon', twice. Use a different name. Local gi:GameIcon = .... 'One variable, named "gi". For Local tempGI:GameIcon = EachIn GiList 'Another variable, named "tempGI". -------------------------- After this, both variables exist and can be accessed: gi = ... tempGI = ... 'This didn't just exist inside the For loop, it exists in the same scope as the For loop. A For loop in BlitzMax does not create a new scope. The code is not working because you're not adding anything to GiList. It's an empty list. |
| ||
The numbering also looks wrong. gi.Num=gi.Num+1 That sets gi = 1 for every type. You probably want gi.Num=x which successively assigns 1,2 etc. |
| ||
you forgot to start yout code with the command SUPERSTRICT. With a SUPERSTRICT at the beginning it will run immediately. It is always a good choice to use SUPERSTRICT. Floyd is right: it has to be "gi.Num=x". I already wrote this in my last post too. In the moment, when you create a new "gi" the num is always 0. Ergo "gi.num=gi.num+1" sets num to 1. When you use a Event-driven game, you should take care that some events really happen. If not your game will hang. Best choice is to add a Tímer: Global Timer:TTimer=CreateTimer(10) Then you have a repeatly event and your display will be drawn every 100msec. If you try to find bugs it is always a good choice to add PRINT lines in your code to understand where (in the code) your programm works at the moment. Try this: SuperStrict Import MaxGui.Drivers Graphics 800,600 Type GameIcon Field img:TImage,num:Int End Type Global GiList:TList= New TList For Local x:Int=1 To 2 Local gi:GameIcon = New GameIcon gi.Num=x gi.img:TImage=LoadImage("icon"+gi.Num+".png") GiList.AddLast gi Next Print "START" Global Timer:TTimer=CreateTimer(60) While Not KeyDown(1) Print "RUNNING" Cls Select WaitEvent() Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE End End Select For Local gi:GameIcon = EachIn GiList DrawImage gi.Img,0,0 Print gi.num Next Flip Wend EndGraphics End |
| ||
Caton: I never did have compile errors That weird that is, I get Compile Error Duplicate identifier 'gi'. It may be because I don't have the proper libraries on my PC. I don't use BlitzMax, I use Monkey-X. Hope you get it sorted. ;-) |