Manual under construction. Some parts are incomplete or may change.
NyraServer
Nyra 0.5.4.28
NyraServer is the addon that connects your game to the Nyra server. It takes care of the sign-in, the session, the remote players and the keys, with conditions, actions and expressions ready to use: you don't have to write any message by hand.
Note
This page describes NyraServer 0.5.0.0. The entries added recently (Is disconnect reason, On level changed, the usernames, the facing in tile mode, Send face, On player turned) have not been tried in Construct yet: only 1.0.0.2 has been tried in Construct.
Information
Type
Plugin, global and single (one per project)
Construct version
r495 or newer
Properties
None
NyraServer has no properties: you write the server address in the Connect action.
Conditions
Connection
CONDITION
WHAT IT DOES
On connected
The connection is open.
On disconnected
The connection closed (by you, by the server or because of a network problem). The session state is already cleared.
Is connected
True as long as the connection is open.
Is disconnect reason
True if the last close had this reason. Parameter Reason: Duplicate login, Account suspended (reserved: the server does not use it today), Server stopping, Other. If the close was normal (for example with Disconnect) no reason is true.
Auth
CONDITION
WHAT IT DOES
On register success
The registration was accepted. See RegisteredUsername.
On auth error
Registration or sign-in refused. See AuthErrorContext and AuthErrorReason.
On welcome
Sign-in succeeded. The session state is already full.
Is logged in
True after On welcome, false after the connection closes.
Session
CONDITION
WHAT IT DOES
Is movement mode
True if the server movement mode is the one you chose. Parameter Mode: Tile, Platform, EightDir.
Players
CONDITION
WHAT IT DOES
On player joined
Another player came in. The Player… expressions refer to them.
On player moved
A player moved. It fires for yours too: use Is my player.
On player turned
A player turned on the spot, without moving (Tile mode). It fires for yours too: use Is my player.
On player left
A player left. The Player… expressions refer to them.
Is my player
True if the player of the current event is yours.
For each other player
Loop over all the other players (yours excluded). The Player… expressions refer to the current one.
Game events
CONDITION
WHAT IT DOES
On game event
A game event arrived. Parameter Name: the name of the event (empty = any).
On level changed
The level changed: LevelJSON and MyStartX/MyStartY are up to date and the list of the other players is empty.
Raw messages
CONDITION
WHAT IT DOES
On any message
Fires for every message received. Parameter Type: the type of the message (empty = any).
Errors
CONDITION
WHAT IT DOES
On error
Something went wrong. See ErrorCode and ErrorMessage.
Actions
Connection
ACTION
WHAT IT DOES
Connect
Opens the connection to the server. Parameter URL: the address you copy from the Overview (it starts with wss:// online, or ws:// for tests on your computer). It is an asynchronous action: you can use Wait for previous actions. It gives the already-connected error if a connection is already open and connection-failed if the address is not valid or the server does not answer. Every Connect always ends with On disconnected.
Disconnect
Closes the connection (code 1000). If you are not connected it does nothing.
Auth
ACTION
WHAT IT DOES
Register
Creates an account. Parameters Username, Email, Password. It does not sign you in to the game: wait for On register success, then use Login.
Login
Signs you in to the game. Parameters Identifier (username or email) and Password. If it works On welcome fires, if it fails On auth error.
Input
ACTION
WHAT IT DOES
Set control
A single action for the keys, in every mode. Parameters Control (Left, Right, Jump, Run, Up, Down) and State (1 = pressed, 0 = released). You can call it every tick: if nothing changes it sends nothing. In Tile a held key keeps walking, one step after the other. Controls that do not apply in the current mode (for example Jump in Tile and in 8 directions) are ignored without an error.
Send tile move
Tile only. Sends one precise step. Parameters DX and DY (-1, 0 or 1), for example for a click on a cell. For held keys use Set control.
Send face
Tile only. Turns your character on the spot, without moving it. Parameter Facing in degrees: 0 right, 90 down, 180 left, 270 up; any other value gives the invalid-argument error. The server accepts at most 10 requests per second and ignores the others: call it when the direction changes, not every tick. If the direction is the same nothing happens.
Raw messages
ACTION
WHAT IT DOES
Send raw message
Sends any message to the server. Parameters Type and Payload JSON. An invalid payload gives the invalid-json error and sends nothing.
Expressions
You write NyraServer. followed by the name, for example NyraServer.PlayerFacing. The Player… expressions refer to the current player: the one of the trigger in progress or of the For each other player loop.
Connection
EXPRESSION
WHAT IT RETURNS
DisconnectCode
The code of the last close: 1000 (a normal close, for example you did Disconnect; the server also closes with 1000 for an internal error), 4000 (protocol error), 1006 (server unreachable), 4001 or 4003 (see Errors).
DisconnectReason
The reason of the last close: duplicate-login, account-suspended (reserved: the server does not use it today), server-stopping, or the close text sent by the server for the other codes. Empty for normal closes (1000, 1001, 1006) and for those decided by the addon (4000).
Auth
EXPRESSION
WHAT IT RETURNS
RegisteredUsername
The username confirmed by the last registration.
AuthErrorContext
register or login.
AuthErrorReason
The reason for the refusal (see Errors).
Session
EXPRESSION
WHAT IT RETURNS
ProtocolVersion
The protocol version.
MovementMode
tile, platform or eightdir.
MyPlayerId
The identifier of your player.
MyUsername
The username of your player.
MyStartX, MyStartY
Your starting position (at sign-in or when the level changes).
MyStartOnGround
In Platform: 1 if you start standing on the ground.
MyStartFacing
Your starting direction, in degrees (0 right, 90 down, 180 left, 270 up). In Tile it is saved with the account (90 for a new account); in Platform it is 0. In 8 directions: multiples of 45.
Gravity, JumpVelocity, VoidY
In Platform: gravity, jump speed and the threshold for falling into the void.
WalkSpeed, RunSpeed
Walking and running speed (Platform and 8 directions).
PlayerWidth, PlayerHeight
Width and height of the collision area (Platform and 8 directions).
HitboxOffsetY
8 directions only: vertical shift of the collision area (positive = downwards).
PlayerCollision
8 directions only: 1 if the players block each other.
TileSize, MoveDurationMs
In Tile: the size of a cell and the duration of a step.
MapWidthTiles, MapHeightTiles
In Tile: the width and height of the map in cells.
LevelJSON
The level as text (empty if there is none).
Players
EXPRESSION
WHAT IT RETURNS
OtherPlayerCount
How many other players there are (yours excluded).
PlayerId
The identifier of the current player.
PlayerUsername
The username of the current player.
PlayerX, PlayerY
The position of the current player. In Tile: the cell they arrived in (top left corner). In Platform: the centre of the feet. In 8 directions: the centre.
PlayerFacing
The last known direction, in degrees. In Tile only 0, 90, 180 or 270. In 8 directions: multiples of 45. In Platform it is always 90. If the server never sent it, it is 90.
PlayerMoving
8 directions only: 1 if the last message changed the position, 0 if the player only turned. Outside 8 directions it is always 0.
PlayerRunning
In Platform and 8 directions: 1 if they are running.
PlayerVelocityY
In Platform: vertical speed.
PlayerOnGround
In Platform: 1 if they are on the ground.
PlayerFromX, PlayerFromY
In Tile: the cell the last step started from.
PlayerMoveDurationMs
In Tile: the duration of the last step.
Game events
EXPRESSION
WHAT IT RETURNS
GameEventName
The name of the last game event.
GameEventPlayerId
The player of the last game event (empty if it concerns everyone).
GameEventDataJSON
The data of the last game event, as text.
GameEventData(Key)
One value of the data, by name. If the name is not there it returns empty text and gives the missing-key error.
Raw messages and errors
EXPRESSION
WHAT IT RETURNS
LastMessageType
The type of the last message received.
LastMessageJSON
The last message received, as text.
ErrorCode
The code of the last error.
ErrorMessage
The message of the last error, readable.
Errors
Errors arrive in three different ways. Every error also writes a line in the browser console (F12).
Addon errors: On error
Read them with ErrorCode and ErrorMessage.
CODE
WHAT IT MEANS
WHAT TO DO
connection-failed
The address is wrong or the server is off, or too many windows are open from the same address (at most 10).
Check the address and that the server is on.
not-connected
You did an action without being connected.
Do Connect first and wait for On connected.
not-logged-in
Game action before On welcome.
Put the game actions after On welcome or under Is logged in.
invalid-argument
Empty field in Login or Register, empty Type in Send raw message, non-numeric DX or DY in Send tile move, Send face other than 0, 90, 180, 270.
Fix the value.
wrong-movement-mode
Action of another mode (for example Send tile move in Platform).
The server is not compatible with this version of the addon. The connection closes with code 4000.
Update the addon or the server: they are not compatible.
no-move-response
In Tile: the server did not answer a step.
Press the direction again.
Refusals on registration and sign-in: On auth error
Read them with AuthErrorContext (register or login) and AuthErrorReason.
REASON
WHAT IT MEANS
invalid-credentials
Wrong username or password.
username-taken, email-taken
The username or the email is already taken.
too-many-attempts
Login: too many wrong attempts, more than 5 per name or 20 from the same address in a minute: wait a minute. Register: more than 3 registrations an hour from the same address, even successful ones.
invalid-input
The registration data is not valid. The detail is in LastMessageJSON.
account-suspended
The account is suspended (reserved: the server does not use it today). You see a suspended account at Login, in On auth error.
login-in-progress
You did Login again before the answer to the first one arrived.
Closes decided by the server: On disconnected
Read them with DisconnectCode, DisconnectReason or the Is disconnect reason condition.
CODE
REASON
WHAT IT MEANS
WHAT TO DO
4001
duplicate-login
The same account came in from another window. The new sign-in wins.
Warn the player and do not reconnect on your own.
4003
server-stopping
The server is stopping or restarting.
Try again later.
4000
(empty)
Protocol error (see above).
Update the addon.
1000
(empty)
A normal close, for example you did Disconnect. The server also closes with 1000 for an internal error.
Nothing.
1006
(empty)
The network dropped or the server does not answer, or too many windows are open from the same address (at most 10).
Check the connection and that the server is on.
Note
The messages from the server that refuse a step or a turn are not errors and do not fire On error. You only see them with the On any message condition.
Compatibility
A new addon works with an older server too: the information that is missing stays empty (or is 90) and a warning appears in the console. An old addon with a newer server ignores the new things.