Nyra Studios
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

TypePlugin, global and single (one per project)
Construct versionr495 or newer
PropertiesNone

NyraServer has no properties: you write the server address in the Connect action.

Conditions

Connection

CONDITIONWHAT IT DOES
On connectedThe connection is open.
On disconnectedThe connection closed (by you, by the server or because of a network problem). The session state is already cleared.
Is connectedTrue as long as the connection is open.
Is disconnect reasonTrue 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

CONDITIONWHAT IT DOES
On register successThe registration was accepted. See RegisteredUsername.
On auth errorRegistration or sign-in refused. See AuthErrorContext and AuthErrorReason.
On welcomeSign-in succeeded. The session state is already full.
Is logged inTrue after On welcome, false after the connection closes.

Session

CONDITIONWHAT IT DOES
Is movement modeTrue if the server movement mode is the one you chose. Parameter Mode: Tile, Platform, EightDir.

Players

CONDITIONWHAT IT DOES
On player joinedAnother player came in. The Player… expressions refer to them.
On player movedA player moved. It fires for yours too: use Is my player.
On player turnedA player turned on the spot, without moving (Tile mode). It fires for yours too: use Is my player.
On player leftA player left. The Player… expressions refer to them.
Is my playerTrue if the player of the current event is yours.
For each other playerLoop over all the other players (yours excluded). The Player… expressions refer to the current one.

Game events

CONDITIONWHAT IT DOES
On game eventA game event arrived. Parameter Name: the name of the event (empty = any).
On level changedThe level changed: LevelJSON and MyStartX/MyStartY are up to date and the list of the other players is empty.

Raw messages

CONDITIONWHAT IT DOES
On any messageFires for every message received. Parameter Type: the type of the message (empty = any).

Errors

CONDITIONWHAT IT DOES
On errorSomething went wrong. See ErrorCode and ErrorMessage.

Actions

Connection

ACTIONWHAT IT DOES
ConnectOpens 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.
DisconnectCloses the connection (code 1000). If you are not connected it does nothing.

Auth

ACTIONWHAT IT DOES
RegisterCreates an account. Parameters Username, Email, Password. It does not sign you in to the game: wait for On register success, then use Login.
LoginSigns 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

ACTIONWHAT IT DOES
Set controlA 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 moveTile 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 faceTile 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

ACTIONWHAT IT DOES
Send raw messageSends 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

EXPRESSIONWHAT IT RETURNS
DisconnectCodeThe 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).
DisconnectReasonThe 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

EXPRESSIONWHAT IT RETURNS
RegisteredUsernameThe username confirmed by the last registration.
AuthErrorContextregister or login.
AuthErrorReasonThe reason for the refusal (see Errors).

Session

EXPRESSIONWHAT IT RETURNS
ProtocolVersionThe protocol version.
MovementModetile, platform or eightdir.
MyPlayerIdThe identifier of your player.
MyUsernameThe username of your player.
MyStartX, MyStartYYour starting position (at sign-in or when the level changes).
MyStartOnGroundIn Platform: 1 if you start standing on the ground.
MyStartFacingYour 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, VoidYIn Platform: gravity, jump speed and the threshold for falling into the void.
WalkSpeed, RunSpeedWalking and running speed (Platform and 8 directions).
PlayerWidth, PlayerHeightWidth and height of the collision area (Platform and 8 directions).
HitboxOffsetY8 directions only: vertical shift of the collision area (positive = downwards).
PlayerCollision8 directions only: 1 if the players block each other.
TileSize, MoveDurationMsIn Tile: the size of a cell and the duration of a step.
MapWidthTiles, MapHeightTilesIn Tile: the width and height of the map in cells.
LevelJSONThe level as text (empty if there is none).

Players

EXPRESSIONWHAT IT RETURNS
OtherPlayerCountHow many other players there are (yours excluded).
PlayerIdThe identifier of the current player.
PlayerUsernameThe username of the current player.
PlayerX, PlayerYThe 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.
PlayerFacingThe 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.
PlayerMoving8 directions only: 1 if the last message changed the position, 0 if the player only turned. Outside 8 directions it is always 0.
PlayerRunningIn Platform and 8 directions: 1 if they are running.
PlayerVelocityYIn Platform: vertical speed.
PlayerOnGroundIn Platform: 1 if they are on the ground.
PlayerFromX, PlayerFromYIn Tile: the cell the last step started from.
PlayerMoveDurationMsIn Tile: the duration of the last step.

Game events

EXPRESSIONWHAT IT RETURNS
GameEventNameThe name of the last game event.
GameEventPlayerIdThe player of the last game event (empty if it concerns everyone).
GameEventDataJSONThe 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

EXPRESSIONWHAT IT RETURNS
LastMessageTypeThe type of the last message received.
LastMessageJSONThe last message received, as text.
ErrorCodeThe code of the last error.
ErrorMessageThe 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.

CODEWHAT IT MEANSWHAT TO DO
connection-failedThe 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-connectedYou did an action without being connected.Do Connect first and wait for On connected.
not-logged-inGame action before On welcome.Put the game actions after On welcome or under Is logged in.
invalid-argumentEmpty 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-modeAction of another mode (for example Send tile move in Platform).Use Is movement mode.
already-connectedConnect while you are already connected.Do Disconnect first.
invalid-jsonWrong payload in Send raw message.Fix the payload.
malformed-messageThe server sent an invalid message.It does not depend on your game: report it.
missing-keyGameEventData with a key that is not there.Check the name of the key.
missing-protocol-version, unsupported-protocol-versionThe 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-responseIn 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.

REASONWHAT IT MEANS
invalid-credentialsWrong username or password.
username-taken, email-takenThe username or the email is already taken.
too-many-attemptsLogin: 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-inputThe registration data is not valid. The detail is in LastMessageJSON.
account-suspendedThe account is suspended (reserved: the server does not use it today). You see a suspended account at Login, in On auth error.
login-in-progressYou 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.

CODEREASONWHAT IT MEANSWHAT TO DO
4001duplicate-loginThe same account came in from another window. The new sign-in wins.Warn the player and do not reconnect on your own.
4003server-stoppingThe 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.