Blitz3D+ Command Reference

Field variable[,variable2,...]

Parameters

variable - the name of a field, with an optional type suffix (# float, $ string, or a .typename for another object)

variable2 (optional) - further fields, comma separated

Description

Declares one or more fields inside a Type block.

Fields are the per-object variables of a custom type. Every object you create with New gets its own copy of each one, so a hundred bullets have a hundred separate x and y values.

You can declare several on one line or spread them over many - Field x#,y#,speed# is the same as three separate Field lines. Use the normal type suffixes: plain for integers, # for floats, $ for strings. A field can also hold another object by naming its type, as in Field owner.player, which is how you link things together - a bullet that knows who fired it, or an inventory entry that knows its item.

New objects start with all their fields cleared: numbers at 0, strings empty, and object fields at Null. You do not need to initialise them yourself, though setting them right after New keeps the code readable.

Field only makes sense between Type and End Type. Read and write fields on an object with a backslash: b\x# = b\x# + b\speed#.

See also: Type, End Type, New, Null.

Example

; Field Example
; -------------

Type Enemy
    ; Each Field is a variable that every Enemy object carries
    Field name$
    Field hp
    Field speed#
End Type

; Every object made with New gets its own copy of the Fields
e.Enemy=New Enemy
e\name="Scout"
e\hp=20
e\speed=2.5

e.Enemy=New Enemy
e\name="Brute"
e\hp=80
e\speed=0.75

; Read the Fields back with the \ operator
For e.Enemy=Each Enemy
    Print e\name+": "+e\hp+" hp, speed "+e\speed
Next

Print ""
Print "Press any key to close the example"
WaitKey

End

Index