Console outputs Uncaught TypeError for .add in JavaScript
I am making a 2D platformer game in which I am using the Phaser-framework (version 3.15.1) to make life easier, and a Tiled map for the first level of the game. I have exported the map from Tiled as a .json
file, and read into the main JS file. However, in my index HTML file, where all fo teh JS files are ran from it comes up with the following error:
Uncaught TypeError: Cannot read
property 'add' of index.html:17 undefined
at index.html:17
at index.html:20
Here is the relevant code:
<head>
<meta charset="UTF-8">
<title>Nightly Neighbours Using Phaser</title>
<script type="text/javascript" src = "js/phaser.js"></script>
<script type="text/javascript" src = "js/phaser-arcade-physics.js">
</script>
<script type="text/javascript" src = "js/Boot.js"></script>
<script type="text/javascript" src = "js/Preload.js"></script>
<script
type="text/javascript"src="js/NightlyNeighbours1WithPhaser.js">
</script>
<script type="text/javascript">
(function() {
game = new Phaser.Game(window.innerWidth *
window.devicePixelRatio,
window.innerHeight * window.devicePixelRatio, Phaser.AUTO);
game.state.add("Boot", Boot);
game.state.add("Preload", Preload);
game.state.add("NightlyNeighbours1WithPhaser", Main);
game.state.start("Boot");
})();
</script>
</head>
The error refers to lines 17 - 20
Thanks a lot!
javascript html phaser-framework tiled
|
show 1 more comment
I am making a 2D platformer game in which I am using the Phaser-framework (version 3.15.1) to make life easier, and a Tiled map for the first level of the game. I have exported the map from Tiled as a .json
file, and read into the main JS file. However, in my index HTML file, where all fo teh JS files are ran from it comes up with the following error:
Uncaught TypeError: Cannot read
property 'add' of index.html:17 undefined
at index.html:17
at index.html:20
Here is the relevant code:
<head>
<meta charset="UTF-8">
<title>Nightly Neighbours Using Phaser</title>
<script type="text/javascript" src = "js/phaser.js"></script>
<script type="text/javascript" src = "js/phaser-arcade-physics.js">
</script>
<script type="text/javascript" src = "js/Boot.js"></script>
<script type="text/javascript" src = "js/Preload.js"></script>
<script
type="text/javascript"src="js/NightlyNeighbours1WithPhaser.js">
</script>
<script type="text/javascript">
(function() {
game = new Phaser.Game(window.innerWidth *
window.devicePixelRatio,
window.innerHeight * window.devicePixelRatio, Phaser.AUTO);
game.state.add("Boot", Boot);
game.state.add("Preload", Preload);
game.state.add("NightlyNeighbours1WithPhaser", Main);
game.state.start("Boot");
})();
</script>
</head>
The error refers to lines 17 - 20
Thanks a lot!
javascript html phaser-framework tiled
The error means thatgame.state
isundefined
. That is, there is either no property on thegame
object called "state", or there is but it has no value.
– Pointy
Jan 1 at 18:38
what is ingame.state
?
– Daniel A. White
Jan 1 at 18:38
I didn't think, that it was necessary to definegame.state
so it has nothing it at the moment @DanielA.White @Pointy
– Tea_Cups
Jan 1 at 18:41
How would I definegame.state
? @Pointy
– Tea_Cups
Jan 1 at 18:41
I have no idea; I don't know how that library works. If you're expecting it to have that particular API (the.add()
method, and probably other things) then I don't think it's something you can do in your own code; it seems like it'd be something that the Phaser code would initialize.
– Pointy
Jan 1 at 18:44
|
show 1 more comment
I am making a 2D platformer game in which I am using the Phaser-framework (version 3.15.1) to make life easier, and a Tiled map for the first level of the game. I have exported the map from Tiled as a .json
file, and read into the main JS file. However, in my index HTML file, where all fo teh JS files are ran from it comes up with the following error:
Uncaught TypeError: Cannot read
property 'add' of index.html:17 undefined
at index.html:17
at index.html:20
Here is the relevant code:
<head>
<meta charset="UTF-8">
<title>Nightly Neighbours Using Phaser</title>
<script type="text/javascript" src = "js/phaser.js"></script>
<script type="text/javascript" src = "js/phaser-arcade-physics.js">
</script>
<script type="text/javascript" src = "js/Boot.js"></script>
<script type="text/javascript" src = "js/Preload.js"></script>
<script
type="text/javascript"src="js/NightlyNeighbours1WithPhaser.js">
</script>
<script type="text/javascript">
(function() {
game = new Phaser.Game(window.innerWidth *
window.devicePixelRatio,
window.innerHeight * window.devicePixelRatio, Phaser.AUTO);
game.state.add("Boot", Boot);
game.state.add("Preload", Preload);
game.state.add("NightlyNeighbours1WithPhaser", Main);
game.state.start("Boot");
})();
</script>
</head>
The error refers to lines 17 - 20
Thanks a lot!
javascript html phaser-framework tiled
I am making a 2D platformer game in which I am using the Phaser-framework (version 3.15.1) to make life easier, and a Tiled map for the first level of the game. I have exported the map from Tiled as a .json
file, and read into the main JS file. However, in my index HTML file, where all fo teh JS files are ran from it comes up with the following error:
Uncaught TypeError: Cannot read
property 'add' of index.html:17 undefined
at index.html:17
at index.html:20
Here is the relevant code:
<head>
<meta charset="UTF-8">
<title>Nightly Neighbours Using Phaser</title>
<script type="text/javascript" src = "js/phaser.js"></script>
<script type="text/javascript" src = "js/phaser-arcade-physics.js">
</script>
<script type="text/javascript" src = "js/Boot.js"></script>
<script type="text/javascript" src = "js/Preload.js"></script>
<script
type="text/javascript"src="js/NightlyNeighbours1WithPhaser.js">
</script>
<script type="text/javascript">
(function() {
game = new Phaser.Game(window.innerWidth *
window.devicePixelRatio,
window.innerHeight * window.devicePixelRatio, Phaser.AUTO);
game.state.add("Boot", Boot);
game.state.add("Preload", Preload);
game.state.add("NightlyNeighbours1WithPhaser", Main);
game.state.start("Boot");
})();
</script>
</head>
The error refers to lines 17 - 20
Thanks a lot!
javascript html phaser-framework tiled
javascript html phaser-framework tiled
asked Jan 1 at 18:35
Tea_CupsTea_Cups
167
167
The error means thatgame.state
isundefined
. That is, there is either no property on thegame
object called "state", or there is but it has no value.
– Pointy
Jan 1 at 18:38
what is ingame.state
?
– Daniel A. White
Jan 1 at 18:38
I didn't think, that it was necessary to definegame.state
so it has nothing it at the moment @DanielA.White @Pointy
– Tea_Cups
Jan 1 at 18:41
How would I definegame.state
? @Pointy
– Tea_Cups
Jan 1 at 18:41
I have no idea; I don't know how that library works. If you're expecting it to have that particular API (the.add()
method, and probably other things) then I don't think it's something you can do in your own code; it seems like it'd be something that the Phaser code would initialize.
– Pointy
Jan 1 at 18:44
|
show 1 more comment
The error means thatgame.state
isundefined
. That is, there is either no property on thegame
object called "state", or there is but it has no value.
– Pointy
Jan 1 at 18:38
what is ingame.state
?
– Daniel A. White
Jan 1 at 18:38
I didn't think, that it was necessary to definegame.state
so it has nothing it at the moment @DanielA.White @Pointy
– Tea_Cups
Jan 1 at 18:41
How would I definegame.state
? @Pointy
– Tea_Cups
Jan 1 at 18:41
I have no idea; I don't know how that library works. If you're expecting it to have that particular API (the.add()
method, and probably other things) then I don't think it's something you can do in your own code; it seems like it'd be something that the Phaser code would initialize.
– Pointy
Jan 1 at 18:44
The error means that
game.state
is undefined
. That is, there is either no property on the game
object called "state", or there is but it has no value.– Pointy
Jan 1 at 18:38
The error means that
game.state
is undefined
. That is, there is either no property on the game
object called "state", or there is but it has no value.– Pointy
Jan 1 at 18:38
what is in
game.state
?– Daniel A. White
Jan 1 at 18:38
what is in
game.state
?– Daniel A. White
Jan 1 at 18:38
I didn't think, that it was necessary to define
game.state
so it has nothing it at the moment @DanielA.White @Pointy– Tea_Cups
Jan 1 at 18:41
I didn't think, that it was necessary to define
game.state
so it has nothing it at the moment @DanielA.White @Pointy– Tea_Cups
Jan 1 at 18:41
How would I define
game.state
? @Pointy– Tea_Cups
Jan 1 at 18:41
How would I define
game.state
? @Pointy– Tea_Cups
Jan 1 at 18:41
I have no idea; I don't know how that library works. If you're expecting it to have that particular API (the
.add()
method, and probably other things) then I don't think it's something you can do in your own code; it seems like it'd be something that the Phaser code would initialize.– Pointy
Jan 1 at 18:44
I have no idea; I don't know how that library works. If you're expecting it to have that particular API (the
.add()
method, and probably other things) then I don't think it's something you can do in your own code; it seems like it'd be something that the Phaser code would initialize.– Pointy
Jan 1 at 18:44
|
show 1 more comment
1 Answer
1
active
oldest
votes
In Phaser 3 there was a change from using state
s to instead using scene
s. Based upon your code it looks like you're using Phaser 2 code with the Phaser 3 library.
There's a great official tutorial (with Part 5 starting with the code aspect, since it appears you might have your environment setup already) that covers Phaser 3.
From that tutorial, the defining of the Phaser.Game
looks something like the following:
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 200 }
}
},
scene: {
preload: preload,
create: create
}
};
var game = new Phaser.Game(config);
You can also add new scenes to the game, by calling game.scene.add(...)
.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997956%2fconsole-outputs-uncaught-typeerror-for-add-in-javascript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In Phaser 3 there was a change from using state
s to instead using scene
s. Based upon your code it looks like you're using Phaser 2 code with the Phaser 3 library.
There's a great official tutorial (with Part 5 starting with the code aspect, since it appears you might have your environment setup already) that covers Phaser 3.
From that tutorial, the defining of the Phaser.Game
looks something like the following:
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 200 }
}
},
scene: {
preload: preload,
create: create
}
};
var game = new Phaser.Game(config);
You can also add new scenes to the game, by calling game.scene.add(...)
.
add a comment |
In Phaser 3 there was a change from using state
s to instead using scene
s. Based upon your code it looks like you're using Phaser 2 code with the Phaser 3 library.
There's a great official tutorial (with Part 5 starting with the code aspect, since it appears you might have your environment setup already) that covers Phaser 3.
From that tutorial, the defining of the Phaser.Game
looks something like the following:
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 200 }
}
},
scene: {
preload: preload,
create: create
}
};
var game = new Phaser.Game(config);
You can also add new scenes to the game, by calling game.scene.add(...)
.
add a comment |
In Phaser 3 there was a change from using state
s to instead using scene
s. Based upon your code it looks like you're using Phaser 2 code with the Phaser 3 library.
There's a great official tutorial (with Part 5 starting with the code aspect, since it appears you might have your environment setup already) that covers Phaser 3.
From that tutorial, the defining of the Phaser.Game
looks something like the following:
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 200 }
}
},
scene: {
preload: preload,
create: create
}
};
var game = new Phaser.Game(config);
You can also add new scenes to the game, by calling game.scene.add(...)
.
In Phaser 3 there was a change from using state
s to instead using scene
s. Based upon your code it looks like you're using Phaser 2 code with the Phaser 3 library.
There's a great official tutorial (with Part 5 starting with the code aspect, since it appears you might have your environment setup already) that covers Phaser 3.
From that tutorial, the defining of the Phaser.Game
looks something like the following:
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 200 }
}
},
scene: {
preload: preload,
create: create
}
};
var game = new Phaser.Game(config);
You can also add new scenes to the game, by calling game.scene.add(...)
.
answered Jan 2 at 14:20
James SkempJames Skemp
5,01784877
5,01784877
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997956%2fconsole-outputs-uncaught-typeerror-for-add-in-javascript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The error means that
game.state
isundefined
. That is, there is either no property on thegame
object called "state", or there is but it has no value.– Pointy
Jan 1 at 18:38
what is in
game.state
?– Daniel A. White
Jan 1 at 18:38
I didn't think, that it was necessary to define
game.state
so it has nothing it at the moment @DanielA.White @Pointy– Tea_Cups
Jan 1 at 18:41
How would I define
game.state
? @Pointy– Tea_Cups
Jan 1 at 18:41
I have no idea; I don't know how that library works. If you're expecting it to have that particular API (the
.add()
method, and probably other things) then I don't think it's something you can do in your own code; it seems like it'd be something that the Phaser code would initialize.– Pointy
Jan 1 at 18:44