New typename
Parameters
| typename - the name of a type declared with a Type block |
Description
|
Creates a new object of a custom type and returns a handle to it. b.bullet = New bullet makes one bullet and points the variable b at it. All of its fields start cleared - numbers at 0, strings empty, object fields at Null - so you normally follow New with a few lines setting it up. The new object is added to the end of that type's list, which means Last will find it and a For ... = Each loop will reach it. If you want it somewhere other than the end, create it and then move it with Insert. This is the moment a thing comes into existence in your game: firing a weapon, spawning a wave, adding a particle to an explosion, picking up an item. There is no fixed limit to create against - make as many as you need and destroy them with Delete when they are done. Do remember the destroying half. An object stays in its list, and in memory, until something deletes it. Bullets that leave the screen without being deleted will keep piling up and slowly strangle your frame rate. See also: Type, Delete, Field, Insert, Each, Null. |
Example
; New Example ; ----------- Type Enemy Field name$ Field hp End Type ; New creates a fresh Enemy object and adds it to the end of the collection e.Enemy=New Enemy e\name="Scout" e\hp=20 e.Enemy=New Enemy e\name="Grunt" e\hp=50 e.Enemy=New Enemy e\name="Brute" e\hp=80 ; The collection keeps them in the order New created them Print "Squad after three New calls:" For e.Enemy=Each Enemy Print " "+e\name+" ("+e\hp+" hp)" Next Print "" Print "Press any key to close the example" WaitKey End
Index