Hi i am trying to do the Treasure Hunter Javascript game project but i cant cause it keeps stopping. this problem happened yesterday and now it won’t stop. it was working fine a few days ago. I need this resolved ASAP because i can’t go any further. here is a screen shot of the issue when i click the game to start it up.
Hey @codemasterzk72. I’m Lillian, Codecademy’s Community Manager. Happy to take a look into this for you. Can you let me know the steps to reproduce the issue you’re experiencing? Here’s what I’ll need from you:
- Expected behavior – How should this be working?
- Actual behavior - What’s it actually doing? When you say “it keeps stopping”, can you elaborate on that?
- Steps to reproduce – Walk me through how to reproduce this bug. I’ll follow along and once I see the issue, I’ll create a ticket for our team to fix it! Also, please include a link to this project. That’s always helpful.
How does that sound? Keep me posted, and thank you!
hi, the following is happening in order
(1) when i click the game screen from the title screen it should start up my game as my code should be correct according to solution when i checked if it was my code.
(2) what is actually happening is it is failing to load the game screen and slowing down the whole firefox page as a result. BTW still happening as of this morning. by “stopping” i mean when i click the game screen to start or test the game, it goes black from the title screen and my firefox page comes to a halt completely and suggests for me to close my lesson page in order for the browser to run faster.
(3) this error was only made possible after STEP 18 when finished creating the decideCoinLocations() function in the create() code block
here is a link to the project: https://www.codecademy.com/paths/create-video-games-with-phaser/tracks/game-dev-learn-javascript-arrays-and-loops/modules/game-dev-project-arrays-and-loops/projects/treasure-hunter
thanks for sharing all that here @codemasterzk72, going to DM you to get a bit more information.
has the support staff said anything yet? as far as I know the error still persists and as someone paying pro yearly this is very frustrating.
Hi codemasterzk72, apologies for this. Sonny here from Curriculum. I just tried it again with your code in Chrome and it seems like it’s working fine. Can you try again today? It might’ve been an engineering backend issue.
its still the same problem. I am starting over and seeing if that works. But I must say I am really bummed out about this whole thing.
starting over helped. thanks for all your assistance.
Really sorry about it codemasterzk72. Next time, feel free to tag me if there are any more problems! I wonder if it’s because you just happened to start this project when we made some changes.
Keep in touch,
Sonny
I’m sorry but this lesson along with business outfitter bob are just completely bugged. now it is just blanking with no explanation.
here is my code as I was instructed to write during the lesson so you can understand my frustration with this content even on chrome.
let plot;
let grid = [];
let coinCollection = [];
let playerCoins = 0;
let compCoins = 0;
class GameScene extends Phaser.Scene {
constructor() {
super({
key: 'GameScene'
})
}
preload() {
// We have preloaded our images such as the background, the coins, the digging image etc.
this.load.image('board', 'https://content.codecademy.com/courses/learn-phaser/Treasure%20Hunter/Gameboard%20Default.png', {
frameWidth: 240,
frameHeight: 320
});
this.load.image('gold', 'https://content.codecademy.com/courses/learn-phaser/Treasure%20Hunter/gold%20coin.png');
this.load.image('playerGold', 'https://content.codecademy.com/courses/learn-phaser/Treasure%20Hunter/gold%20coin%20shine.png');
this.load.image('dig', 'https://content.codecademy.com/courses/learn-phaser/Treasure%20Hunter/dug%20hole.png');
this.load.image('blank', 'https://content.codecademy.com/courses/learn-phaser/Treasure%20Hunter/blank.png'); // These are the actual images / tiles that load on top of 'board'
}
create() {
// The background is provided below
this.add.sprite(240, 320, 'board');
this.add.sprite(240, 550, 'gold');
// Create the for loops to create the grid
for(let x = 46; x < 437; x += 78) {
for(let y = 46; y < 437; y += 78) {
plot = this.add.sprite('blank')
grid.push(plot)
}
}
// Create the coins from the grid created above
this.add.sprite(x, y, 'gold')
// Create the function which decides the coin locations here
function decideCoinLocations() {
while (coinCollection.length < 5) {
let randIdx = Math.floor(Math.random() * grid.length)
let selectedPlot = grid[randIdx]
if(coinCollection.indexOf(selectedPlot) === -1) {
coinCollection.push(selectedPlot)
}
}
decideCoinLocations()
} // End of Create
update() {
// Determine winner and scores
let determineWInner = this.determineWinner()
let playerScore = this.add
.text(195, 487, ' ' + playerCoins + ' ', {
font: '16px Helvetica',
fill: '#000000',
padding: {
x: 6,
y: 7
},
backgroundColor: '#ffffff'
})
let compScore = this.add
.text(430, 487, ' ' + compCoins + ' ', {
font: '16px Helvetica',
fill: '#000000',
padding: {
x: 6,
y: 7
},
backgroundColor: '#ffffff'
})
// Input / marker creation
this.input.setHitArea(grid).on('gameobjectover', function (pointer, gameObject) {
gameObject.setTint(0xff0000);
});
this.input.setHitArea(grid).on('gameobjectout', function (pointer, gameObject) {
gameObject.clearTint();
});
//Check on player click
this.input.setHitArea(grid).on('gameobjectdown', function (pointer, gameObject) {
if (gameObject.texture.key === 'blank') {
game.input.enabled = false;
let clickedPlot = gameObject
//playerCheck starts here
function playerCheck() {
for (var i = 0; i < coinCollection.length; i++) {
if (clickedPlot === coinCollection[i]) {
playerCoins++
clickedPlot.setTexture('playerGold')
break;
} else {
clickedPlot.setTexture('dig')
}
}
if (playerCoins !== 3) {
setTimeout(function () {
compTurn()
}, 450);
}
}
playerCheck();
} else {
function input() {
game.input.enabled = true;
}
setTimeout(function () {
input()
}, 1000)
}
})
// Computer turn
function compTurn() {
let compChoice;
let item;
let items = [];
function singleIndex() {
item = Math.floor(Math.random() * grid.length);
for (let i = 0; i < 1; i++) {
if (items.indexOf(item) !== null) {
compChoice = {
c: grid[item],
key: grid[item].texture.key
}
items.push(item)
} else {
singleIndex()
}
}
}
singleIndex()
if (compChoice.key !== 'blank') {
compTurn()
} else {
for (let i = 0; i < coinCollection.length; i++) {
if (compChoice.c === coinCollection[i]) {
compCoins++
grid[item].setTexture('gold')
break;
} else {
grid[item].setTexture('dig')
}
}
}
function input() {
game.input.enabled = true;
}
setTimeout(function () {
input()
}, 1000)
}
} //end Update
// Helper Functions
endGame() {
this.scene.stop('GameScene');
this.scene.start('EndScene');
game.input.enabled = true;
}
determineWinner() {
if (playerCoins === 3 || compCoins === 3) {
this.endGame()
}
}
} // end GameScene
I am really frustrated because I like these lessons. I find them fascinating. and there is nothing more infuriating when they won’t work. In the meantime I am moving on to another lesson. All I’m doing is spending empty time on this one when I could be halfway through another lesson.
Hi @codemasterzk72!
Sorry for the late response!! Apologies for the meh experience - part of it has to do with Phaser and part of it just how much screen space we had for our lessons and projects. (Phaser doesn’t give helpful error messages, and we didn’t have space for our console). However! some good troubleshooting tips:
- It might be the browser (Phaser works better on FireFox for some reason sometimes)
- Use the browser console, see this article and skip down to “Debug your JavaScript Using the Console Tool”
- Always always always run your code after writing a line (or a block). Since Phaser doesn’t have helpful error messages, sometimes you just get a blank screen. If you know that your last line of code caused the blank screen it’s easier to debug.
- The walkthrough videos might help! But again combine it with the above mentioned tips for better efficiency
Now, on to the practical side. When I ran your code, I noticed some errors in the console about an Unexpected identifier ‘{’ meaning there’s some extra {
in your code or that it’s missing the closing }
.
After collapsing some of the function blocks I adding in some missing }
. See:
And I got rid of the blank screen! (But the game’s still not fully playable). I don’t have the full context for how you approached this project - but it might be easier to start this project over from scratch and using the mentioned tips (or move on to the next lesson/project with those tips in mind). You can also view the solution here too to see how we implemented the solution.
Hope this helps!
Kenny
Hi, I was trying to open the solution file and this is what I got:
Can you show me what’s wrong?
You need to extract the files first after downloading. I use 7-win as it’s free. Then you need to open index.html to see the code using inspect.