Entities and other objects within TypeDeclaration?
Blitz3D Forums/Blitz3D Programming/Entities and other objects within TypeDeclaration?
| ||
Pardon me for my ignorance on types, but I have a question which may turn out to be stupid. I've got a quad entity created but I want to be able to create it inside a Type. Rather than creating it seperately in another variable. I'm not sure of the syntax or even if what I'm doing is possible. Basically I want to create a type with custom fields in it ; For example:- Type alien Field x,y Field quad Field texture End Type and then be able to access stuff like PositionEntity newalien\quad,x,y EntityTexture newalien\quad,newalien\texture but I can't seem to figure out how to define texture and quad in the alien type declaration. Something C++ object style like this:- Type alien Field Int x,Int y Field Quad quad Field Image texture End Type I've created a quad already and normally I access that by going:- new_sprite_object = CopyEntity(quad) But I want to automate this and stick it inside the type somewhere. Maybe like:- function newalien(x,y,image$) newalien = New alien newalien\quad = CopyEntity(quad) newalien\image = Loadimage(image$) return newalien end function If I could just figure out how to create an entity when I create a new type then I'd be sorted. I hope I'm making sense. HELP! :) |
| ||
function CreateANewAlien(quad,texture,x,y,z) myalien.alien=new alien myalien\quad=copyentity(quad) myalien\image=texture myalien\x=x myalien\y=y myalien\z=z positionentity myalien\quad,x,y,z end function or if you want the function to return the type record that has just been created: function NewAlien.alien(quad,texture,x,y,z) myalien.alien=new alien myalien\quad=copyentity(quad) myalien\image=texture myalien\x=x myalien\y=y myalien\z=z return myalien.alien end function |
| ||
Cheers Matty :) I'll give them a try. I think:- function NewAlien.alien(quad,texture,x,y,z) was what I was looking. Is that kind of like a function that can only be accessed by the type? Like in C++ objects:- alien.create(quad,texture,x,y,z); If you see what I mean. |
| ||
You cannot use "alien.create" as blitz doesn't work that way. The function name determines what type of value the function returns. So you could use , for example, the name of the function determines the type of data it can return. So - if you wanted to return a string you would include "$" as part of the function name eg you could call a function : function ThisFuntionReturnsText$(parameter1,parameter2) {some code goes here} return SomeString$ end function or if you wanted to return a float then replace the $ with #. By default they return integers. If you wanted to return a record for a particular type then you would name the function as I did above: function Newalien.alien(parameters...) return MyAlienRecord.Alien end function If you are asking does Blitz support "methods" for "objects" then I would probably have to say no. |
| ||
It's not that I Want to create methods for objects (although that could be nice) I just want to store entities and images inside types when I create them, which according to what you're saying seems possible. I've been busy these last few days so I'll be sure to tell you if I've succeeded. Thanks again :) |