Linking Objects Field
BlitzMax Forums/BlitzMax Programming/Linking Objects Field
| ||
I'm trying to link object fields together, but I keep getting a object is NULL is there something I'm missing with this or am I doing it completely wrong..?Type TMain Extends TEngine Field winMain:TGadget Field mnuMain:TGadget Field panMain:TGadget Field tolMain:TGadget Field timer:TTimer Method Create:TMain() Local ww:Int=800, wh:Int=600 Local wx:Int=(GadgetWidth(Desktop())-ww)/2 Local wy:Int=(GadgetHeight(Desktop())-wh)/2 Local ws:Int=WINDOW_TITLEBAR|WINDOW_MENU|WINDOW_CLIENTCOORDS|WINDOW_STATUS winMain=CreateWindow("Editor ( Version "+Version+" )",wx,wy,ww,wh,Null,ws) Local px:Int=0 Local py:Int=26 Local pw:Int=(GadgetWidth(winMain)) Local ph:Int=(GadgetHeight(winMain))-26 panMain=CreatePanel(px,py,pw,ph,winMain) SetPanelColor panMain,192,192,192 tolMain=CreateToolBar("icon.png",0,0,0,0,winMain) run Return Self End Method Method RunTime(event:TEvent) Select event.id Case EVENT_WINDOWCLOSE End End Select End Method End Type Type TMap Extends TMain Field canMap:TGadget Method Create:TMap() Local cx:Int=8 Local cy:Int=8 Local cw:Int=512 Local ch:Int=512 'ERROR IS HERE!!! canMap=CreateCanvas(cx,cy,cw,ch,panMain) 'ERROR IS HERE!!! timer=CreateTimer(60) run Return Self End Method Method RunTime(event:TEvent) Select event.id Case EVENT_TIMERTICK RedrawGadget canMap Case EVENT_GADGETPAINT DrawMap End Select End Method Method DrawMap() SetGraphics CanvasGraphics(canMap) SetClsColor 255,255,255 Cls SetColor 0,207,0 DrawLine 0,0,511,0 DrawLine 0,0,0,511 DrawLine 511,0,511,511 DrawLine 0,511,511,511 SetColor 255,255,255 Flip End Method End Type Once I better understand the way types work in Blitzmax, I will be making a better editor, but for now this is all I know about it :( |
| ||
A method is performed against a type instance so you can't really use it to create itself. For actions performed against the type you use functions rather than methods. Once you have your instance you can use methods against it to perform actions on that instance. Bit rambly but hope it makes sense. The Beginners Guide to Blitzmax covers most of what you need to get going. |
| ||
Your code looks fine, generally. I assume you are creating your instances like this : myMap = New TMap.Create() which is cool. You should add this tho, to your TMap.Create(): Method Create:TMap() Super.Create() ... which will instantiate your TMain variables. :o) |
| ||
Thanks for the help Brucey... It works now... I don't fully understand whatz all going on with the Super command, but once I put it there it worked great.. |
| ||
super calls the base classes method/field of that name |