Game Development 2 Level 28 Game of Coins Step 4

Hello!! I’m having a lot of trouble with this one. On line 122 it’s asking me to put an if statement. I did that but it’s saying “Error, CheckTimeScore is not defined” and I didn’t even use the function. well, here’s my code! >:)

// Step 4 of creating a Pac-Man style arcade game.

// The game layout and items. Scroll down.
game.spawnXY("forest", 16, 16);
game.spawnXY("forest", 32, 16);
game.spawnXY("forest", 48, 16);
game.spawnXY("forest", 64, 16);
game.spawnXY("forest", 16, 32);
game.spawnXY("forest", 32, 32);
game.spawnXY("forest", 48, 32);
game.spawnXY("forest", 64, 32);
game.spawnXY("forest", 16, 48);
game.spawnXY("forest", 32, 48);
game.spawnXY("forest", 48, 48);
game.spawnXY("forest", 64, 48);

game.spawnXY("bronze-coin", 16, 8);
game.spawnXY("bronze-coin", 24, 8);
game.spawnXY("bronze-coin", 32, 8);
game.spawnXY("bronze-coin", 48, 8);
game.spawnXY("bronze-coin", 56, 8);
game.spawnXY("bronze-coin", 64, 8);
game.spawnXY("bronze-coin", 72, 8);

game.spawnXY("bronze-coin", 8, 16);
game.spawnXY("bronze-coin", 24, 16);
game.spawnXY("bronze-coin", 40, 16);
game.spawnXY("bronze-coin", 56, 16);
game.spawnXY("bronze-coin", 72, 16);

game.spawnXY("bronze-coin", 8, 24);
game.spawnXY("bronze-coin", 16, 24);
game.spawnXY("bronze-coin", 24, 24);
game.spawnXY("bronze-coin", 32, 24);
game.spawnXY("bronze-coin", 40, 24);
game.spawnXY("bronze-coin", 48, 24);
game.spawnXY("bronze-coin", 56, 24);
game.spawnXY("bronze-coin", 64, 24);
game.spawnXY("bronze-coin", 72, 24);

game.spawnXY("bronze-coin", 24, 32);
game.spawnXY("bronze-coin", 56, 32);

game.spawnXY("bronze-coin", 8, 40);
game.spawnXY("bronze-coin", 16, 40);
game.spawnXY("bronze-coin", 24, 40);
game.spawnXY("bronze-coin", 32, 40);
game.spawnXY("bronze-coin", 40, 40);
game.spawnXY("bronze-coin", 48, 40);
game.spawnXY("bronze-coin", 56, 40);
game.spawnXY("bronze-coin", 64, 40);
game.spawnXY("bronze-coin", 72, 40);

game.spawnXY("bronze-coin", 8, 48);
game.spawnXY("bronze-coin", 24, 48);
game.spawnXY("bronze-coin", 40, 48);
game.spawnXY("bronze-coin", 56, 48);
game.spawnXY("bronze-coin", 72, 48);

game.spawnXY("bronze-coin", 8, 56);
game.spawnXY("bronze-coin", 16, 56);
game.spawnXY("bronze-coin", 24, 56);
game.spawnXY("bronze-coin", 32, 56);
game.spawnXY("bronze-coin", 48, 56);
game.spawnXY("bronze-coin", 56, 56);
game.spawnXY("bronze-coin", 64, 56);
game.spawnXY("bronze-coin", 72, 56);

game.spawnXY("mushroom", 40, 8);
game.spawnXY("mushroom", 8, 32);
game.spawnXY("mushroom", 72, 32);
game.spawnXY("mushroom", 40, 56);

game.score = 1000;
// The duration of power-ups.
game.powerDuration = 6;
// The time until a power-up runs out. Used for UI.
game.powerTime = 0;
// The time a power-up expires. Used internally.
game.powerEndTime = 0;
ui.track(game, "time");
ui.track(game, "score");
// Adding ui for game.powerTime:
ui.track(game, "powerTime");

game.addCollectGoal();
game.addSurviveGoal();

var player = game.spawnPlayerXY("knight", 8, 8);
player.maxSpeed = 30;

// The function make the player big and strong.
function powerPlayerUp() {
    player.scale = 2;
    player.attackDamage = 100;
    game.powerEndTime = game.time + game.powerDuration;
}

// The function return the player in the normal state.
function powerPlayerDown() {
    player.scale = 1;
    player.attackDamage = 1;
}

function onCollect(event) {
    var player = event.target;
    var item = event.other;
    if (item.type == "bronze-coin") {
        game.score += 1;
    }
    if (item.type == "mushroom") {
        game.score += 5;
        // Use powerPlayerUp to strengthen the player:
        powerPlayerUp();
    }
}

function onCollide(event) {
    var player = event.target;
    var other = event.other;
    // If other is a "scout" and the player's scale is 2:
    if (other == "scout" and player.scale = 2) {
        
    }
        // Defeat the other with the defeat method:
        
}


player.on("collect", onCollect);
// Assign the event handler for the player's "collide" event:


var generator = game.spawnXY("generator", 41, 31);
generator.spawnType = "scout";
generator.spawnDelay = 6;

function onSpawn(event) {
    var unit = event.target;
    unit.maxSpeed = 8;
    unit.attackDamage = player.maxHealth;
    while (true) {
        // Enemies run away from the big player.
        if (player.scale == 2) {
            unit.behavior = "RunsAway";
        }
        else {
            unit.behavior = "AttacksNearest";
        }
    }
}

function onDefeat(event) {
    // Increase game.score for defeated enemies:
    game.score += 10;
}

game.setActionFor("scout", "spawn", onSpawn);
game.setActionFor("scout", "defeat", onDefeat);


function checkTimeScore() {
    game.score -= 0.5;
    if (game.score < 0) {
        game.score = 0;
    }
}

function checkPowerTimer() {
    // Remaining power time.
    game.powerTime = game.powerEndTime - game.time;
    if (game.powerTime <= 0) {
        game.powerTime = 0;
        // If the player is powered, then it's time to power-down.
        if (player.scale == 2) {
            powerPlayerDown();
        }
    }
}

// Lets combine all the time based functions.
function checkTimers() {
    checkTimeScore();
    checkPowerTimer();
}

while (true) {
    checkTimers();
}

// Win the game.

Thanks so Much!! -Amira >:)

Calling on @Bryukh again cuz I don’t do Game Dev lol

Line 122 seems to be this. Try other.type == "scout" instead of other == "scout".

2 Likes

It didn’t work still. it said the same thing when I clicked play.

1 Like

For javascript "and " is &

actualy its two of them
like this
if(other.type=="scout" && player.scale==2)
shouldnt the player scale also be == insead of just one = ?

Oh yea sorry haven’t did javascript in a while.

@Amira_Saadi does this work?

No it still didn’t work.

1 Like

Uhh you didn’t do what Falcon said.

I said to do 2 &&'s :grin:

I did that as well.

plaer.scale=2

change it to
player.scale==2
shouldnt it be 2 == sign and not one? :grin:

1 Like

Ahh!! That worked! But I’m confused when it asked me to “//Defeat the other with the defeat method:” "//Defeat the other with the defeat method:" Where exactly would I put the defeat inside the method when it didn’t work for me the first time?

1 Like

??
sorry i have no clue :grin:
I dont do game dev
but if any post helped you solved it mark it as solved

1 Like

ummm it is solved right?

1 Like

I tried doing the defeat with other. is there supposed to be a other.(defeat);? I tried doing that and with parenthesis and Idk what I’m doing wrong.

1 Like

so its not solved???
sorry i am kinda confused

1 Like

Thats ok, I’ll try to figure it out, thanks so much for helping with that!!

1 Like

So its not solved. :grin:
sorry I couldnt help for the other part…

1 Like