Your Create function within the Button type is not returning the object it creates, so you're passing a null object when you call g.addgadget(b)
Change the create function in Button to this:
And you should be fine.
Change the create function in Button to this:
Function Create:button(x , y , width:Float , height:Float , text$) Local t:button=New button t.x = x t.y = y t.width = width t.height = height t.text = text If img = Null img=gui_type.gui_pointer.button_img img2=gui_type.gui_pointer.button_over_img Return t EndIf
And you should be fine.