Я использую NodeJS и Socket.io. Это мой index.jsNodeJS SyntaxError: ожидаемое выражение, получено '<'
var app = require('http').createServer(handler);
var io = require('socket.io').listen(app);
var fs = require('fs');
app.listen(3000);
console.log("Listening on port 3000");
function handler(req, res) {
fs.readFile(__dirname + '/index.html', function(err, data) {
if(err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
Вот мой index.html
<!DOCTYPE html>
<html>
<head>
<script src="http://localhost:3000/socket.io/socket.io.js"></script>
<title>Impact Game</title>
<style type="text/css">
html,body {
background-color: #333;
color: #fff;
font-family: helvetica, arial, sans-serif;
margin: 0;
padding: 0;
font-size: 12pt;
}
#canvas {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
}
</style>
<script src="lib/impact/impact.js"></script>
<script src="lib/game/main.js"></script>
</head>
<body>
<canvas id="canvas"></canvas>
</body>
</html>
Когда я иду на локальный хост: 3000, я получаю «SyntaxError: ожидается выражение, получил '<' main.js: 1: 0" .
Учебник, которым я старался следовать, был для ImpactJS + NodeJS + Socket.IO, чтобы сделать многопользовательскую игру, но это самый дальний у меня с ней до сих пор.
Здесь пока содержание main.js
ig.module(
'game.main'
)
.requires(
'impact.game',
'impact.font'
)
.defines(function(){
MyGame = ig.Game.extend({
// Load a font
font: new ig.Font('media/04b03.font.png'),
init: function() {
// Initialize your game here; bind keys etc.
},
update: function() {
// Update all entities and backgroundMaps
this.parent();
// Add your own, additional update code here
},
draw: function() {
// Draw all entities and backgroundMaps
this.parent();
// Add your own drawing code here
var x = ig.system.width/2,
y = ig.system.height/2;
this.font.draw('It Works!', x, y, ig.Font.ALIGN.CENTER);
}
});
// Start the Game with 60fps, a resolution of 320x240, scaled
// up by a factor of 2
ig.main('#canvas', MyGame, 60, 320, 240, 2);
});
В чем содержание 'main.js'? – jeerbl
У вас есть блуждающая скобка где-то ... – timothyclifford
Если ошибка в 'main.js', это файл, который вы должны были разместить. – Pointy