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
So i’m on… Create Video Games w/phaser -
3 - Learn Javascript - Arrays & Loops - Project - Treasure Hunter Project.
When you click the GameStart scene to run the game, it’s just a blank screen.
I’m only on step 5 so syntax wouldn’t be the issue. I’ve tried it on Chrome, Firefox, Safari, etc.
Any help would be appreciated because I would like to continue this course.
thank you
mtrtmk
December 11, 2022, 3:04pm
2
Can you copy-paste your code here?
You can click the </>
button and then post your code between the pair of three backticks.
```
Paste code on new line between backticks
```
// Create your global variables here
let plot;
let grid = [];
let coinCollection = [];
let playerCoins = 0;
let computerCoins = 0;
class GameScene extends Phaser.Scene {
constructor() {
super({
key: 'GameScene'
})
}
preload() {
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');
}
create() {
this.add.sprite(240, 320, 'board');
this.add.sprite(240, 550, 'gold');
} // 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'
})
// 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
All I did was create the variables at the top. And this.add.sprite(240, 550, 'gold') under
create `.
mtrtmk
December 12, 2022, 3:37am
4
You wrote:
let computerCoins = 0;
but I don’t see this variable being used anywhere else in the code pasted by you.
I do see a variable compCoins
being used though.
I am not a subscriber, so I can’t view the instruction steps. Are you sure the instructions asked you to create the variable computerCoins
? Perhaps they asked you to create,
let compCoins = 0;
yep. that was problem, which I finally figured out yesterday. appreciate though, man. thanks for your help.