Fast Foodie: Make your customers hungry

Private Prinny is getting really annoyed now! The instructions for this project are just plain BAD.

Step 18 + 19: I add this at the bottom of create()
gameState.currentMeal = this.add.group();
currentMeal.add(fullnessValue = 0);

Step 20 + 21: I edit the meter width
// Edit the meterWidth
let meterWidth = customerContainer.fullnessCapacity * 10;
customerContainer.meterContainer = this.add.container(0, customer.y + (meterWidth / 2));

// Add the customerContainer.meterContainer to customerContainer
customerContainer.meterContainer.add(customerContainer);

Step 22: I edit j
for (let j = 0; j < customerContainer.fullnessCapacity; j++)

Now, something somewhere in these steps is causing an error which stops my game running entirely. But I have no idea what.

Creating Phaser groups is introduced during this project, and then we’re asked to add another property to the group we’ve only just been given some very basic instructions on how to use.

This is really, reallyreallyreally bad instruction.

I need help, and I hate asking for help. There is nowhere I can even check the work I’ve done so far either so I have to wait until someone can help.

When I open the console the error I’m getting is “currentMeal is not defined!” Which I can’t say is surprising since with this task I’m being asked to do something that hasn’t been covered before, which shows no other examples, and doesn’t have any solution anywhere either.

Needless to say, Private Prinny is pretty pissed now and to make things worse I have to wait for some sort of answer…

Well, without seeing your code, it’s a bit difficult to offer any help. Also, and more importantly, the tone of your post is not conducive to receiving helpful responses from volunteers. If you’d like to post your code, please follow the guidelines here, and I’ll take a look when I have the time.

I gave the snippets of what I had been doing in place of the entire code. As for my tone it’s because I’m very frustrated that for this particular project there isn’t any way for me to check what I have done and it is reliant on the input from other people. Which means waiting when I could be working.

For browser compatibility, that’s an easy issue to fix. All it needs is a notice on this particular project since it has issues stating, “This project is known to have issues with x browser, we recommend using y browsers.” People like to use the browsers they are used to.

Help from volunteers is always appreciated and I have no problems with them. However, if there is a problem that needs fixing, then it’s up to the higher ups to fix it. The sooner that a problem can be resolved, the better the end experience will be for other users.

const gameState = {
  score: 0,
  starRating: 5,
  currentWaveCount: 1,
  customerIsReady: false,
  readyForNextOrder: true,
  customersServedCount: 0,
  cam: {},
  gameSpeed: 3,
  currentMusic: {},
  totalWaveCount: 3,
  countdownTimer: 1500
}

// Gameplay scene
class GameScene extends Phaser.Scene {
  constructor() {
    super({ key: 'GameScene' })
  }
  updateCustomerCountText() {
    gameState.customersLeftCount = gameState.totalCustomerCount - gameState.customersServedCount;
    return gameState.customersLeftCount;
  }
  preload() {
    // Preload images
    const baseURL = 'https://codecademy-content.s3.amazonaws.com/courses/learn-phaser/fastfoodie/';
    this.load.image('Chef', `${baseURL}art/Chef.png`);
    this.load.image('Customer-1', `${baseURL}art/Customer-1.png`);
    this.load.image('Customer-2', `${baseURL}art/Customer-2.png`);
    this.load.image('Customer-3', `${baseURL}art/Customer-3.png`);
    this.load.image('Customer-4', `${baseURL}art/Customer-4.png`);
    this.load.image('Customer-5', `${baseURL}art/Customer-5.png`);
    this.load.image('Floor-Server', `${baseURL}art/Floor-Server.png`);
    this.load.image('Floor-Customer', `${baseURL}art/Floor-Customer.png`);
    this.load.image('Tray', `${baseURL}art/Tray.png`);
    this.load.image('Barrier', `${baseURL}art/Barrier.png`);
    this.load.image('Star-full', `${baseURL}art/Star-full.png`);
    this.load.image('Star-half', `${baseURL}art/Star-half.png`);
    this.load.image('Star-empty', `${baseURL}art/Star-empty.png`);

    // Preload song
    this.load.audio('gameplayTheme', [
      `${baseURL}audio/music/2-gameplayTheme.ogg`,
      `${baseURL}audio/music/2-gameplayTheme.mp3`
    ]); // Credit: "Pixel Song #18" by hmmm101: https://freesound.org/people/hmmm101

    // Preload SFX
    this.load.audio('placeFoodSFX', [
      `${baseURL}audio/sfx/placeFood.ogg`,
      `${baseURL}audio/sfx/placeFood.mp3`
    ]); // Credit: "action_02.wav" by dermotte: https://freesound.org/people/dermotte

    this.load.audio('servingCorrectSFX', [
      `${baseURL}audio/sfx/servingCorrect.ogg`,
      `${baseURL}audio/sfx/servingCorrect.mp3`
    ]); // Credit: "Video Game SFX Positive Action Long Tail" by rhodesmas: https://freesound.org/people/djlprojects

    this.load.audio('servingIncorrectSFX', [
      `${baseURL}audio/sfx/servingIncorrect.ogg`,
      `${baseURL}audio/sfx/servingIncorrect.mp3`
    ]); // Credit: "Incorrect 01" by rhodesmas: https://freesound.org/people/rhodesmas

    this.load.audio('servingEmptySFX', [
      `${baseURL}audio/sfx/servingEmpty.ogg`,
      `${baseURL}audio/sfx/servingEmpty.mp3`
    ]); // Credit: "Computer Error Noise [variants of KevinVG207's Freesound#331912].wav" by Timbre: https://freesound.org/people/Timbre

    this.load.audio('fiveStarsSFX', [
      `${baseURL}audio/sfx/fiveStars.ogg`,
      `${baseURL}audio/sfx/fiveStars.mp3`
    ]); // Credit: "Success 01" by rhodesmas: https://freesound.org/people/rhodesmas

    this.load.audio('nextWaveSFX', [
      `${baseURL}audio/sfx/nextWave.ogg`,
      `${baseURL}audio/sfx/nextWave.mp3`
    ]); // Credit: "old fashion radio jingle 2.wav" by rhodesmas: https://freesound.org/people/chimerical
  }

  create() {
    // Stop, reassign, and play the new music
    gameState.currentMusic.stop();
    gameState.currentMusic = this.sound.add('gameplayTheme');
    gameState.currentMusic.play({ loop: true });

    // Assign SFX
    gameState.sfx = {};
    gameState.sfx.placeFood = this.sound.add('placeFoodSFX');
    gameState.sfx.servingCorrect = this.sound.add('servingCorrectSFX');
    gameState.sfx.servingIncorrect = this.sound.add('servingIncorrectSFX');
    gameState.sfx.servingEmpty = this.sound.add('servingEmptySFX');
    gameState.sfx.fiveStars = this.sound.add('fiveStarsSFX');
    gameState.sfx.nextWave = this.sound.add('nextWaveSFX');

    // Create environment sprites
    gameState.floorServer = this.add.sprite(gameState.cam.midPoint.x, 0, 'Floor-Server').setScale(0.5).setOrigin(0.5, 0);
    gameState.floorCustomer = this.add.sprite(gameState.cam.midPoint.x, gameState.cam.worldView.bottom, 'Floor-Customer').setScale(0.5).setOrigin(0.5, 1);
    gameState.table = this.add.sprite(gameState.cam.midPoint.x, gameState.cam.midPoint.y, 'Barrier').setScale(0.5);

    // Create player and tray sprites
    gameState.tray = this.add.sprite(gameState.cam.midPoint.x, gameState.cam.midPoint.y, 'Tray').setScale(0.5);
    gameState.player = this.add.sprite(gameState.cam.midPoint.x, 200, 'Chef').setScale(0.5);

    // Display the score
    gameState.scoreTitleText = this.add.text(gameState.cam.midPoint.x, 30, 'Score', { fontSize: '15px', fill: '#666666' }).setOrigin(0.5);
    gameState.scoreText = this.add.text(gameState.cam.midPoint.x, gameState.scoreTitleText.y + gameState.scoreTitleText.height + 20, gameState.score, { fontSize: '30px', fill: '#000000' }).setOrigin(0.5);

    // Display the wave count
    gameState.waveTitleText = this.add.text(gameState.cam.worldView.right - 20, 30, 'Wave', { fontSize: '64px', fill: '#666666' }).setOrigin(1, 1).setScale(0.25);
    gameState.waveCountText = this.add.text(gameState.cam.worldView.right - 20, 30, gameState.currentWaveCount + '/' + gameState.totalWaveCount, { fontSize: '120px', fill: '#000000' }).setOrigin(1, 0).setScale(0.25);

    // Display number of customers left
    gameState.customerCountText = this.add.text(gameState.cam.worldView.right - 20, 80, `Customers left: ${gameState.customersLeftCount}`, { fontSize: '15px', fill: '#000000' }).setOrigin(1);
    
    // Generate wave group
    gameState.customers = this.add.group();
    this.generateWave();
    gameState.currentMeal = this.add.group(); 
    currentMeal.add(fullnessValue = 0);
  }

  update() {
    if (gameState.readyForNextOrder === true) {
      gameState.readyForNextOrder = false;
      gameState.customerIsReady = false;
    }
  }

  /* WAVES */
  // Generate wave
  generateWave() {
    // Add the total number of customers per wave here:
    gameState.totalCustomerCount = Math.ceil(Math.random() * 10) * gameState.currentWaveCount;
    this.updateCustomerCount = gameState.customerCountText.setText (`Customers left: ${this.updateCustomerCountText()}`)
    for (let i = 0; i < gameState.totalCustomerCount; i++) {
      // Create your container below and add your customers to it below:
      const customerContainer = this.add.container(gameState.cam.worldView.right + (200 * i), gameState.cam.worldView.bottom - 140);
      gameState.customers.add(customerContainer);
      // Customer sprite randomizer
      let customerImageKey = Math.ceil(Math.random() * 5);

      // Draw customers here!
      const customer = this.add.sprite(0, 0, `Customer-${customerImageKey}`).setScale(0.5);
      gameState.currentCustomer = gameState.customers.children.entries[gameState.customersServedCount];
      customerContainer.add(customer);
      gameState.customerMove = this.tweens.add ({
      targets: gameState.currentCustomer,
      duration: 1000,
      delay: 100,
      angle: 90,
      x: gameState.player.x,
      ease: "Power2",
      onComplete: function () {
        gameState.customerIsReady = true;
        gameState.customerContainer.meterContainer.visible = true;
      }
    })
      // Fullness meter container
      customerContainer.fullnessMeter = this.add.group();

      // Define capacity
      customerContainer.fullnessCapacity = Math.ceil(Math.random() * 5 * gameState.totalWaveCount);

      // If capacity is an impossible number, reshuffle it until it isn't
      while (customerContainer.fullnessCapacity === 12 || customerContainer.fullnessCapacity === 14) {
        customerContainer.fullnessCapacity = Math.ceil(Math.random() * 5) * gameState.totalWaveCount;
      }

      // Edit the meterWidth
      let meterWidth = customerContainer.fullnessCapacity * 10;
      customerContainer.meterContainer = this.add.container(0, customer.y + (meterWidth / 2));
      
      // Add the customerContainer.meterContainer to customerContainer
      customerContainer.meterContainer.add(customerContainer);

      // Add meter base
      customerContainer.meterBase = this.add.rectangle(-130, customer.y, meterWidth, 33, 0x707070).setOrigin(0);
      customerContainer.meterBase.setStrokeStyle(6, 0x707070);
      customerContainer.meterBase.angle = -90;
      customerContainer.meterContainer.add(customerContainer.meterBase);

      // Add timer countdown meter body
      customerContainer.timerMeterBody = this.add.rectangle(customerContainer.meterBase.x + 22, customer.y + 1, meterWidth + 4, 12, 0x3ADB40).setOrigin(0);
      customerContainer.timerMeterBody.angle = -90;
      customerContainer.meterContainer.add(customerContainer.timerMeterBody);

      // Create container for individual fullness blocks
      customerContainer.fullnessMeterBlocks = [];

      // Create fullness meter blocks
      for (let j = 0; j < customerContainer.fullnessCapacity; j++) {
        customerContainer.fullnessMeterBlocks[j] = this.add.rectangle(customerContainer.meterBase.x, customer.y - (10 * j), 10, 20, 0xDBD53A).setOrigin(0);
        customerContainer.fullnessMeterBlocks[j].setStrokeStyle(2, 0xB9B42E);
        customerContainer.fullnessMeterBlocks[j].angle = -90;
        customerContainer.fullnessMeter.add(customerContainer.fullnessMeterBlocks[j]);
        customerContainer.meterContainer.add(customerContainer.fullnessMeterBlocks[j]);
      }

      // Hide meters
      customerContainer.meterContainer.visible = false;
    }
  } 
}

I assume your error is referencing this line? (There should be a line number at the far right of the console.) Looks like the same type of error from your previous topic. What is currentMeal? Doesn’t it belong to an object?

Edit: I have not done this project myself. Looking at the instructions, I agree with you that they aren’t very easy to follow. Clicking on the Get Help, and filing bug reports there would be the correct avenue to express your frustrations. The volunteers here on the forums have nothing to do with the curriculum on the main site.

1 Like

currentMeal is a new property that gets assigned to gameState. Then currentMeal gets the property fullnessValue added to it. But we’re using a method which has only just been introduced to us and doesn’t give any examples.

I’m pleased that you can understand my frustration. I don’t know how the command structure works here, whether you’re just making sure people behave and trying to help out, or whether you have any contact with Codecademy employees. I know that in some places moderators have direct contact with the higher ups and can say, “I have a user who is having this problem, I don’t know how to help with it and I don’t understand it myself, can you look at it and see if there are any issues or give a potential solution?”

I will submit a bug report but again that means I’m waiting rather than working which is annoying…

Thanks for the help dood!

Exactly, so to access it, you need gameState.currentMeal, right?
Otherwise, currentMeal by itself is undefined.

At the end of create() I added:
gameState.currentMeal = this.add.group();
currentMeal.add(fullnessValue = 0);

So gameState.currentMeal is defined there as a group I think?
Then I try to add fullnessValue to it (I tried a few different methods)

Then there’s the stuff with the containers. I’m hoping that someone from Codecademy will be able to shed some light on how to do this. Because it’s quite irritating that I can’t complete the final project. But, I haven’t had any sort of response so far.

Fortunately I’ve found somewhere else which offers more advanced lessons in creating videogames with JS and Phaser so that’s keeping me entertained while I wait.