type question
BlitzMax Forums/BlitzMax Beginners Area/type question
| ||
I'm a bit messing around with the demoversion, to be a bit more prepared for the eventual purchase with the GUI module :P I want this: Type tType Field a,b,c Method Blah() Notify "byebye w0rld "+a+" "+b+" "+c End Method End Type test=Create() test.a=1 test.b=2 test.c=3 test.Blah() End Function Create:tType() Return New tType End Function But.. it doesn't work.. :/ So, yes: I want functions to assign a type to a variable. How can I make this work? Note that according to the compiler the actual test=Create() doesn't give errors.. I just can't use members. |
| ||
I don't have Bmax here at the moment, but try doing:test:tType = Create() |
| ||
hm.. that works.. but it spoils the fun a bit.. I was hoping this to be possible *without* the user knowing about types (except for the idea of member-access). So, in short: to make it a bit more analogue to how classic/B+ works, bla=CreateImage, bla=CreateWindow, bla=CreateBank etc. That's more compact than bla:tImage=CreateImage, bla:tWindow=CreateWindow etc. etc. |
| ||
CS_TBL or like thisType tType Field a,b,c Method Blah() Notify "byebye w0rld "+a+" "+b+" "+c End Method Function Create:tType() Local new_type:tType = New tType Return new_type End Function End Type test:tType = tType.Create() test.a=1 test.b=2 test.c=3 test.Blah() End |
| ||
Too complex for what my intentions were :D , my intention was purely the analogy to old blitz/B+. While we're on it.. imagine I've 2 type definitions, called TypeA and TypeB, both completely different. what happens when I do this: bla:TypeA=new TypeB ? |
| ||
It doesn't work. I'm not sure what you can do as far as declaring typeless variables (as it's something I don't do), but another possible solution is to create an abstract base type and then derive everything from that, and only use variables of the base type. Then you can assign it to objects of any subtype you want. Of course, you'll have to rely on either methods derived from the base class, or casting the object anytime you want to do anything with it. |