Problem with OOP
BlitzMax Forums/BlitzMax Programming/Problem with OOP
| ||
In other versions of Blitz, I experienced some limtations with types and started using banks for all my structures. For example, if I have a field in a type that needs to be able to reference multiple types of objects, it isn't possible: Type thing Field target.otherthing If "target" is a .terrain, I can't reference it, unless I use Handle() to store the object integer handle. Then when I am using the target value, I have to do this mess: If Object.terrain(thing\target)<>Null If Object.mesh(thing\target)<>Null If Object.texture(thing\target)<>Null If I use banks, I can just do this: target=PeekInt(thing,THING_TARGET) class=PeekInt(target,OBJECT_CLASS) Also, types don't work well if you are controlling the application with a script, or (theoretically) compiling it to a dll. Has anything changed in BlitzMax that makes this different? Am I overlooking anything important? |
| ||
Yes, make terrain and other shared objects a extended type of a base resource. That way you can do common type check functions and usage functions. No need to know what type it is, just call obj.update() or whatever. |
| ||
What about the handles? Is there a way to store aan object as an integer, and then convert it back into an object without a lot of hassle? |
| ||
What about the handles? Is there a way to store aan object as an integer, and then convert it back into an object without a lot of hassle? No. But like DonnieDarko just said, you don't need to. |
| ||
You do if you want the program to be able to interact with anything external. |
| ||
Here's a dodgy example:Type mytype Extends Object Field blah End Type Type myothertype Extends Object Field jugglies End Type type1:mytype=New mytype type2:myothertype=New myothertype Function stuff(whatever:Object) If mytype(whatever) then Print "mytype was passed!" If Int(whatever) then Print "Integer was passed!" End Function stuff("passing a string will do nothing in this example") stuff(type1) Anyway I think that's how it works, I can't remember exactly off the top of my head and can't find any quick documentation (suprise surprise) to back it up :) |
| ||
Cool, I will read up on the new OOP stuff. |