Connecting the game to the server
On this page you connect your game to the server, sign a player in and make the other players appear. You need to have already installed the addons and the server must be on (see Overview).
The server address
In the Overview of the panel, in the Address to connect the game box, press Copy. The button becomes Copied and the address is in your clipboard. It starts with wss://.
You write the address in the Connect action of NyraServer, between quotes. NyraServer has no properties: the address does not go in the properties bar.
The order things happen in
- Connect opens the connection. When it is open On connected fires.
- If the player has no account, Register creates it. On register success fires. Register does not sign you in to the game: after it you need Login.
- Login signs you in. If it works On welcome fires, if it fails On auth error fires.
- After On welcome come On player joined, On player moved and On player left.
- At the end On disconnected always fires.
A first event sheet
You need a Sprite called Avatar with a text instance variable, pid. These are the events:
- System: On start of layout → NyraServer Connect, with the address copied from the Overview.
- NyraServer: On connected → NyraServer Login, with the username and the password.
- NyraServer: On welcome → create
AvataratNyraServer.MyStartX,NyraServer.MyStartYand setpidtoNyraServer.MyPlayerId.- Sub-event NyraServer: For each other player → create
AvataratNyraServer.PlayerX,NyraServer.PlayerYand setpidtoNyraServer.PlayerId. This way you see the people already in the game.
- Sub-event NyraServer: For each other player → create
- NyraServer: On player joined → create
Avataras in point 3, for the people who come in after you. - NyraServer: On player moved → sub-event:
Avatarwithpidequal toNyraServer.PlayerId→ Set position toNyraServer.PlayerX,NyraServer.PlayerY. - NyraServer: On player left → sub-event:
Avatarwithpidequal toNyraServer.PlayerId→ Destroy.
Also add NyraServer: On error → show NyraServer.ErrorCode & ": " & NyraServer.ErrorMessage. This way you see straight away what is wrong.
Note
On player joined does not fire for the people who were already in the game when you came in. For them you need For each other player inside On welcome, as in point 3.
Note
On player moved fires for your own character too. To tell it apart from the others use the Is my player condition.
Moving your character
For the keys use the Set control action of NyraServer: Is logged in condition, then Keyboard Key is down, then Set control (every tick is fine: if nothing changes it sends nothing). We explain how to move the characters in each mode on the next pages: for 8 directions mode see Nyra 8 Direction.
If something goes wrong
Errors show up in three different ways (On error, On auth error and On disconnected). You find them explained on the NyraServer page, in the Errors part. If you have no On error event, the errors only appear in the browser console (F12 key).