ArcBasicDocs

Custom Types

A type is a kind of object of your own design, with named values called fields. Types suit anything there are many of: aliens, bullets, particles, players. Define one with Type, listing its fields with Field:

Type Alien    Field x#, y#    Field speed#    Field name$End Type

Making and using objects

New makes an object of a type, with every field empty, and gives it back. Keep it in a variable tagged with the type's name, then reach its fields with a backslash:

a.Alien = New Aliena\x = 100a\speed = 2.5a\name = "Zork"Print a\name + " is at " + a\x

A field can be any kind of value, an object of another type, or a fixed-size array (see Basic Arrays). Arrays and functions can hold and pass objects too: Dim fleet.Ship(20), Function Nearest.Alien(x#, y#). A variable for objects holds Null when it holds no object; reaching a field through Null stops the program with an error, so check with If a <> Null when unsure.

Fields with a dot

As well as with a backslash, a field can be reached with a dot, as in many other languages. These pairs mean exactly the same, and the two can be mixed:

player\score = player\score + 10player.score = player.score + 10alien\pos\x = 100alien.pos.x = 100

The dot also still gives a variable its type, as in a.Alien = New Alien. ArcBasic tells the two apart by what it already knows: a.x is a field when a already holds an object whose type has a field called x; otherwise the word after the dot is a type. The backslash always means a field, so use it to be completely clear.

Going through every object

ArcBasic keeps every object of a type in a list, in the order they were made. For ... Each goes through them all, which is how a game moves every alien each frame:

For a.Alien = Each Alien    a\y = a\y + a\speed    If a\y > 600 Then Delete aNext

Delete removes an object, as above; doing so inside a For ... Each is safe. Delete Each Alien removes them all, for example when a level ends.

Moving through the list

First Alien and Last Alien give back the first and last objects of a type, and After a and Before a the ones next to an object, each giving Null past the end. Insert a Before b and Insert a After b move an object to another place in the list. The order matters when it decides what is drawn on top of what.

Handles

Handle(a) turns an object into a whole number that stands for it, which can be kept in an integer array, a bank or a file, and Object.Alien(h) gets the object back, or Null if it has since been deleted or is of another type.