Skip to main content
Version: bleeding-edge 🩸

Packages Communication

All you need to know to communicate between different Packages

In nanos world there are 3 main ways which you can interact with other Packages. In this page we will explain in details how to do so.

Custom Events​


For more information and examples about using Custom Events, please refer to Events.

Communicating with Packages in the same Side​

Custom Events are the easier way to send data or information to other packages:

local my_parameter1 = 123
local my_parameter2 = "hello there"
local my_parameter3 = { important_stuff = "omg!" }

Events.Call("MyAwesomeEvent", my_parameter1, my_parameter2, my_parameter3)
Events.Subscribe("MyAwesomeEvent", function(parameter1, parameter2, parameter3)
Package.Log("Received " .. parameter1) -- Received 123
Package.Log("Received " .. parameter2) -- Received hello there
Package.Log("Received " .. parameter3) -- Received table

Note: Calling events will trigger the event in all Packages.

Sending data through the network​

Sending information through the network is not different from sending in the same side:

local my_parameter1 = "cool data from network"

-- Call this event to all Players
Events.BroadcastRemote("GetThisFromServer", my_parameter1)

local player_02 = GetPlayerSomehow()

-- Or call this event to a specific player
Events.CallRemote("GetThisFromServer", player_02, my_parameter1)
Events.Subscribe("GetThisFromServer", function(parameter1, parameter2, parameter3)
Package.Log("Received " .. parameter1) -- Received cool data from network

Note: Calling network events will trigger the event in all Packages from the other side.

Packages Exported Functions​

Another way of communicating is using Exported Functions. With Exported Functions you can define functions in your Package which can be called by any other Package and have a value returned.


Unlike events, exported functions can return values to the caller. But you can only call Exported Functions from the same side (Server or Client).

Exporting a Function​

For exporting functions, use Package.Export() method:

-- Defines a function which you want to export
function SpawnCoolWeapon(location, rotation)
local cool_weapon = Weapon(location or Vector(), rotation or Rotator(), ...)
return cool_weapon

-- Exports the function to be called by other Packages
Package.Export("SpawnCoolWeapon", SpawnCoolWeapon)

Calling an Exported Function from another Package​

For calling a function exported by another Package, use Package.Call() method:

-- Calls the exported function
local cool_weapon = Package.Call("PackageOne","SpawnCoolWeapon", Vector(), Rotator())

Using Package's RequirePackage​

The last way of communicating between Packages is by loading other Packages inside the current Package:

Package.Log("Hello from Package One!")

Package.Log("Hello from Package Two!")


Hello from Package One!
Hello from Package Two!

This will load the file Index.lua from PackageOne into the VM of PackageOne where you called Package.RequirePackage().

Also the Required Package will be sent to the clients, then you can RequirePackage in the client side too.


It's recommended to set your Required Packages as library and load it as requirement in the Package.toml, this way the package is sent to the clients too.