All you need to know about Classes
All entities in nanos world are represented by a Class. In Lua, classes are represented by tables. That means that every interaction with entities (Players, Characters, Props, etc) are made with Classes/tables methods following an OOP (Object-oriented programming pattern). In this page we will explain more about that.
In nanos world we have 3 types of Classes (or structures):
Static Classes and
If you read our Quick Start guide, you noticed we were spawning entities in the following format:
-- Fait apparaître une entité avec un constructeur
local mon_entite = Entity()
-- Interagir avec l'entité avec ses méthodes
Access to Entities / Spawned Objects Methods are made with
This is how OOP works! You create objects and call functions/catch events on that object. Unlike other scripting games which have tons of global functions and events to interact with entities, nanos world scripting is a modern approach to modern programming.
Classes de base
Under the hood, nanos world Classes follow an Inheritance Pattern, which means we have base parent classes, and it's children which "inherits" all functions, events and properties from them. You will notice that all Classes that can be spawned in the world are Base Actor, for example in Character and Prop it is possible to call the function:
The Base Actor is a very important class in nanos world. It contains the most of methods which are shared through all Classes we have, and also Static Methods to get and retrieve entities directly.
Spawning entities in nanos world is extremely easy and straightforward, let's say we want to spawn a Character:
local mon_personnage = Character()
Each Class will contain it's own Constructor, Properties, Methods and Events.
Check all Classes that nanos world provides in the sidebar SCRIPTING REFERENCE -> Classes item.
Keep in mind that some Classes can only be spawned in the Server, others can only be spawned in the Client.
All classes (but Player) allow you to destroy them with the method
Static Classes in nanos world are Classes which you cannot Spawn. Instead you can use it's methods directly with
For example, if you want to interact with Sun/Sky/Weather, you will need the Sky Static Class:
-- Makes it 9:25 AM
Access to Static Classes / Static Methods are made with
Besides Classes and Static Classes, we have the Utility Classes! Those are mostly structs used in nanos world API such as Vector, Rotator, Color, JSON and some others.
All Utility Classes are Open Sourced at https://github.com/nanos-world/nanos-world-lua-lib. Feel free to push merge requests and suggest changes!