Creating objects on the fly

BlitzMax Forums/BlitzMax Beginners Area/Creating objects on the fly

fhetskr(Posted 2012) [#1]
Alright, back to making noob posts! so my question should be clear: is there a way to have a program make new objects on the fly (while the program is running and already compiled)? an example would be an enemy spawning in off-screen. It would be great if it could also be reffered to inside the code and have it's variables edited, or it's functions used. Thanks in advanced for the help, and thanks for actually reading this whole short post.


Yasha(Posted 2012) [#2]
Creating an object is handled by the "New" operator (syntax: "Local o:MyType = New MyType"). You can access its variables and member functions with the dot operator (syntax: "o.xPos = 10.5 ; o.yPos = 12.6 ; o.normalise(17)").

Objects can in fact only be created while the program is running. There's no such thing as an "object literal" in BlitzMax: you have to use New, or a function that in turn calls New at some inner level (OK, there is also a special syntax for creating and filling arrays, but that's still dynamic even though it has syntax support; and you don't need to think about that right now).

There is no special way to delete an object again. This is the work of the garbage collection system, which will clean up an object once it has detected it is no longer in use.

Last edited 2012