Object class

All classes in Ultra Fractal's formulas ultimately descend from the built-in Object class. The Object class is empty: it does not have any fields or methods.

Having a common base class for all classes is useful because, in combination with casting, it allows you to treat objects of various types equally. For example, you can store various types of objects in the same array:

class Car {
public:
  func Car(int price)
    fPrice = price
  endfunc
  
  int func getPrice()
    return fPrice
  endfunc
  
private:
  int fPrice
}

class Animal {
}
; Create some objects
Object objs[4]
objs[0] = new Car(20000)
objs[1] = new Animal
objs[2] = new Car(30000)
objs[3] = new Car(5000)

; Iterate over all objects
$define debug
int i = 0
while i < 4
  if Car(objs[i])
    print("This is a car that costs $", Car(objs[i]).getPrice())
  elseif Animal(objs[i])
    print("This is an animal")
  endif
  i = i + 1
endwhile

The objs array in this example can store any type of object, and by casting, you can retrieve the original object type.

See Also
Classes
Inheritance
Casting
Image class