Hi all - this is my first live Phaser project, which has so far progressed fairly well. It is a fairly simple turn-based battle game, and you can view a current build here: Bulldroids
Much of the game is implemented now, but it has reached the point where I need to implement multiplayer, which is another first for me.
This tutorial seemed the best for what I need (Create a Basic Multiplayer Game in Phaser 3 with Socket.io – Part 1 – GameDev Academy), and from what I have seen on the forums, it is a popular tutorial.
I have got to the point of adding the server code, then installing socket.io as per the tutorial. However, I get the following error that I can’t fathom how to fix:
"Property ‘listen’ does not exist on type ‘typeof import(“C:/xampp/htdocs/node_modules/socket.io/dist/index”)’.
Referencing this server code:
var express = require('express')
var app = express()
// @ts-ignore
var server = require('http').Server(app)
var io = require('socket.io').listen(server)
io.on('connection', function (socket) {
console.log('a user connected')
socket.on('disconnect', function () {
console.log('user disconnected')
})
})
app.use(express.static(__dirname + '/public'))
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html')
})
server.listen(8081, function () {
console.log(`Listening on ${server.address().port}`)
})
This is the offending line: “var io = require(‘socket.io’).listen(server)”
The second error I get, related to the first, is in the Create function of my first scene:
“Cannot find name ‘io’.”
From this line:
this.socket = io()
All I have done so far is followed the example code in the tutorial. I have also included my index file code below.
In terms of what the game needs to do, it is fairly simple - per round there are only two options each player can select - their move, and their special Pawer move. So the server-side stuff needs to be fairly minimal.
Index code:
<html>
<head>
<title>Bulldroids</title>
</head>
<body>
<script src="/socket.io/socket.io.js"></script>
<div id='bulldroidsgame'>
<script src="//cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.min.js"></script>
<script type="module" src="src/Bulldroids.js"></script>
</div>
</body>
</html>