LogoLogo
  • Introduction
  • sdks
    • Feature Comparison
    • Unity
    • Godot
    • Defold
    • LÖVE
    • Unreal
  • Quick Start
    • Unity
    • Godot
    • Defold
    • LÖVE
    • Unreal
  • Server Side
    • Entities
    • Chunks
    • Dimensions
    • Events
    • Logging
    • Lua Environment
    • Git Primer
    • Physics
  • HTTP API
    • Authentication
    • Player API
  • Api Reference
    • Entity API
      • Create
      • Message
    • Client API
      • Message
    • Dimension API
      • Create
      • Delete
      • List
    • Events API
      • on_player_join
      • on_player_leave
    • Table API
      • Append
      • Remove
      • Join
    • Util API
      • Time
      • TimeMillis
    • HTTP Request API
      • Get
      • Post
      • Put
      • Delete
    • Physics API
      • NewBody
      • NewBoxShape
      • NewSphereShape
Powered by GitBook
On this page
  • Pre-requisites
  • Installation
  • SDK Object
  • sdk.init
  • sdk.join
  • sdk.update
  • sdk.message
  • sdk.server_to_client
  • Game World Objects
  • Entity Object
  • Chunk Object
  • API
  • SDK Object
  • Entity Object
  • Chunk Object
  1. sdks

LÖVE

PreviousDefoldNextUnreal

Last updated 8 days ago

The LÖVE SDK integrates our multiplayer platform with LÖVE. The library provides methods and variables to use within your game client code - these communicate changes in state from your server side simulation to the game client itself.

If you are new here, we recommend starting with the .

Pre-requisites

  • LÖVE v11.0+

Installation

The LÖVE SDK can be installed by cloning the latest version from our into your a folder called sdk within your LÖVE game directory.

git clone https://github.com/planetary-processing/love2d-sdk sdk

You can then import the SDK like so:

local sdk = require(“sdk.sdk”)

SDK Object

The SDK object (the imported SDK) can be used to call a variety of functions. These allow you to connect to and pull information from the game server.

  • Establish a connection

Our LÖVE SDK only supports anonymous authentication at present, so you do not need supply a username and password.

function love.load()
    sdk.init(123)
end

  • Join with a player

function love.load()
    sdk.init(123)
    sdk.join()
end

  • Receive server messages

function love.update(dt)
    sdk.update()
end

  • Send messages to the server

sdk.message({x=1, y=-1})

  • Receive manual server messages

sdk.server_to_client = function (message)
    print(message)
end

Game World Objects

Entity Object

-- draw cat entities and player as 'C' and 'P' respectively
function love.draw()
	local player = sdk.entities[sdk.uuid]
	love.graphics.print("P", player.X, -player.Y)

	for id,entity in pairs(sdk.entities) do
		if entity.Type == "cat" then
			-- NOTE Planetary Processing's 'y' axis is inverted from LÖVE 
			love.graphics.print("C", entity.X, -entity.Y)
		end
	end
end

Chunk Object

-- draw chunk borders when the chunk  size is 64
local chunk_size = 64

function love.draw()
    local world_x 
    local world_y 
    
    for id,chunk in pairs(sdk.chunks) do
        world_x = chunk.X * chunk_size
        world_y = chunk.Y * chunk_size
    
        love.graphics.line(world_x, world_y, world_x, world_y + chunk_size)
        love.graphics.line(world_x, world_y, world_x + chunk_size, world_y)
    end	
end

API

Below are reference tables of the API available within LÖVE 's environment.

The SDK exposes various public methods which can be accessed within scripts by importing the SDK like so:

local sdk = require(“sdk.sdk”)

To connect to the server and join with the player, for example:

sdk.init(123)
sdk.join()

SDK Object

Variables

Variable
Type
Description

entities

entities: table({

id: string entity: table )}

List of entities the client can see.

chunks

table: table({

id: string chunk: table )}

List of chunks the client can see.

uuid

string

UUID of the player associated with this client.

server_to_client

function(table)

Function which triggers, when a message is manually sent from the server to this player client.

Methods

Method
Parameters
Description

init

game_id: int

Called to connect to the Planetary Processing servers.

join

None

Spawn into the world.

update

None

Call this method inside love.update.

message

msg: table

Send a message to the player entity on the server.

leave

None

Disconnect the player from the world.

quit

None

Sever the connection to the game.

Entity Object

Fields

Field
Type
Description

EntityID

string

UUID of the entity.

X

float

X coordinate in world units.

Y

float

Y coordinate in world units.

Data

table

Data of the entity.

Type

string

Type of the entity.

Chunk Object

Fields

Field
Type
Description

ID

string

UUID of the chunk.

X

float

X coordinate in chunk units.

Y

float

Y coordinate in chunk units.

Data

table

Data of the chunk.

The first thing you need to do when your game starts is initialise the SDK. To do this, run the function within love.load. This function takes the game_id parameter. The Game ID of your game can be found on the .

After a connection has been established by , the function will spawn the player into the game world.

The function should be called within love.update. It will pass data about entities and chunks from the server to the client, then save it in the SDK object's variables.

You can call the function to send a message to the server. This message will be received by the player.lua file's function on the server.

The variable can store a function. This function triggers when the client receives a message manually sent from the server by .

Game worlds are made up of , which represent objects and creatures, and to represent the world space.

Data about is passed to the LÖVE client using . You can access all the entities within (which can be iterated over) and draw them based each entity's data.

Entities have used to categorise their behaviour on the server side backend. They can be used to access groups of entities. Individual entities can be accessed using the field.

The of the player entity associated with this client is also stored in . This makes it easier to access the player entity directly with sdk.entities[sdk.uuid].

Data about is passed to the LÖVE client using . You can access all the chunk data within sdk.chunks (which can be iterated over).

LÖVE Quickstart Guide
GitHub
sdk.init
web panel
sdk.init
sdk.join
sdk.init
sdk.join
sdk.update
sdk.update
sdk.message
sdk.server_to_client
api.client.Message()
sdk.server_to_client
entities
chunks
entities
sdk.update
sdk.entities
EntityID
sdk.uuid
chunks
sdk.update
sdk.message
EntityID
message
types