Skip to content

oobject

Prune Juice edited this page Apr 22, 2024 · 2 revisions

NOTE: I'm aware this documentation is subpar. I'm working on making it better tho.

Summary

This file contains the OObject class, and methods to initialize OObjects in an efficient manner.

class OObject: Base class for anything that uses the overwriting capabilities of liborange.

obj (string|instance): The object to be overtaken. 

The OObject's purpose is to allow for custom SuperTux objects. You can call OObject with the name of an object in the sector to "overtake" the object, or make a class that extends OObject to add functionality to certain objects.

Here's an example of overtaking an object:


import("liborange.nut") 

// Assume theres a scripted object in the sector caled `object1`. 



::print("is_OObject" in object1) // Prints `false` because `object1` is not an OObject. 



OObject("object1") // Overtakes `object1` and replaces it with an OObject 



::print("is_OObject" in object1) // Prints `true` because `object1` is now an OObject. 

...and heres an example of a class that extends OObject to add/edit functionality of an existing object.


import("liborange.nut") 



class NewObject extends OObject { 

	function get_kewl_string() { // Adding a new function to this object. 

		return "kewl string" 

	} 

	function get_pos_x() { // Overwriting `get_pos_x()` on this object. 

		return object.get_pos_x() / 2 

	} 

} 



// Assume theres a scripted object in the sector caled `object1`. 



object1.get_pos_x() // Prints the x position of `object1`. In this case its 256. 

object1.get_kewl_string() // ERROR: "get_kewl_string()" doesnt exist. 



NewObject(object1) 



object1.get_pos_x() // Prints 128 because we overwrote `get_pos_x()`. 

object1.get_kewl_string() // Prints "kewl string". 

static is_OObject (bool): This object is an OObject!

object (instance): The original object that the OObject overtook. 

object_name (string): The name of the object. (Be prepared for an empty string.) 

odata (table): Custom data stored in the OObject. This is usually set via metamethods and not via 

function display: Wrapper for the display function. For convenience.

ANY (ANY): The object to display. 

function print: Wrapper for the print function. For convenience.

object (ANY): The object to display. 

function set_everything:

stuff (table): 

**DEPRECATED:** This is a stupid function. Dont use it. 

function get_name: Returns the name of the object.

returns string .

class liborange.OObject:

See OObject .

class liborange.Object:

See OObject .

function liborange.convert_to_OObject: Turns every instance currently in sector to an OObject.

sector (table): Defaults to the current sector (or worldmap). 

function liborange.init_objects: Allows you to use one class on many objects at once.

obj_name (string): The prefix of the name of the objects to initialize. 

obj_class (class): The class to be initialized on the oebjcts. 

vargv (...): Extra parameters to pass to the class. 
  • oobject.nut

Clone this wiki locally