pain99 Posted September 2, 2014 Share Posted September 2, 2014 Hiii Sorry for this question but i am new to programming, i just started learning JavaScript (and programming) a week ago and learning phaser three days ago. I want to load some states but it doesn't work, the console says: 'Uncaught ReferenceError: bootState is not defined.' I only coded the basic things, just to see if it works, but it doesn't. Here are the files. index.html:<!DOCTYPE html><html> <head> <script src="http://cdnjs.cloudflare.com/ajax/libs/phaser/2.0.6/phaser.min.js"></script> <script src="game.js"></script> <script src="boot.js"></script> <script src="load.js"></script> </head> <body> <div id="gameDiv"></div> </body></html>boot.js:var bootState = { preload: function(){ game.load.image('progressBar', 'assets/progressBar.png'); }, create: function(){ game.stage.backgrounColor = '#3498db'; game.physics.startSystem(Phaser.Physics.ARCADE); game.state.start('load'); }};load.js:var loadState = { preload: function(){ var loadingLabel = game.add.text(game.world.centerX, 150, 'loading...', {font: '30px Arial', fill: '#ffffff'}); loadingLabel.anchor.setTo(0.5, 0.5); var progressBar = game.add.sprite(game.world.centerX, 200, 'progressBar'); loadingLabel.anchor.setTo(0.5, 0.5); game.load.setPreloadSprite(progressBar); game.load.image('player', 'assets/player.png'); }, create: function(){ //game.state.start('menu'); }};game.js:var game = new Phaser.Game(500, 320, Phaser.AUTO, 'gameDiv');game.state.add('boot', bootState);game.state.add('load', loadState);game.state.start('boot');I don't know what i'm doing wrong. Can anyone help me? And sorry for bad my english. Link to comment Share on other sites More sharing options...
lewster32 Posted September 2, 2014 Share Posted September 2, 2014 The problem is just that game.js is run first, and the states aren't defined at that point. Ttry changing your HTML so it loads the states first, then game last: <script src="boot.js"></script> <script src="load.js"></script> <script src="game.js"></script> ITpaolo and vattujan 2 Link to comment Share on other sites More sharing options...
pain99 Posted September 2, 2014 Author Share Posted September 2, 2014 Wow IT WORKS! Thank you so much! lewster32 1 Link to comment Share on other sites More sharing options...
lewster32 Posted September 2, 2014 Share Posted September 2, 2014 No problem - just remember that at its most basic (ignoring fancy advanced things like hoisting, and all of the program flow that results from functions, if statements and so on) JavaScript is executed left to right, top to bottom, just like a book. If a value is required, you need to make sure it exists first. Link to comment Share on other sites More sharing options...
pain99 Posted September 2, 2014 Author Share Posted September 2, 2014 okay thank you, i'll remember next time Link to comment Share on other sites More sharing options...
ITpaolo Posted November 14, 2016 Share Posted November 14, 2016 On 2.9.2014 at 1:22 PM, lewster32 said: The problem is just that game.js is run first, and the states aren't defined at that point. Ttry changing your HTML so it loads the states first, then game last: <script src="boot.js"></script> <script src="load.js"></script> <script src="game.js"></script> Helped me, ty mate. :-) Link to comment Share on other sites More sharing options...
Recommended Posts