Game Development 2 level 21 Berserker

I’ve been having quite a bit of trouble on this level specifically. Anytime I’m trying to set the game scale, it keep saying “game.PlayerScale” is not defined and I don’t know what that means. I’ll paste my code down below. Thanks a lot!! -Amira >:)

// Mushrooms allow the player to destroy fences for a time.

var player = game.spawnPlayerXY('captain', 12, 34);
player.maxSpeed = 15;
game.addMoveGoalXY(76, 34);
ui.track(game, "time");

// The duration of the mushroom power.
game.powerDuration = 3;
// The time the mushroom power expires at.
game.powerEndTime = 0;

// "mushroom"s are collectable items without default effects.
game.spawnXY("mushroom", 12, 52);
game.spawnXY("mushroom", 12, 16);
game.spawnXY("mushroom", 36, 16);
game.spawnXY("mushroom", 36, 52);
game.spawnXY("mushroom", 56, 12);
game.spawnXY("mushroom", 56, 56);
game.spawnXY("mushroom", 56, 34);

// The event handler for "collect" events.
function onCollect(event) {
    var unit = event.target;
    var item = event.other;
    if (item.type == "mushroom") {
        // "scale" changes the visual size of the unit.
        unit.scale = 2;
        game.powerEndTime = game.time + game.powerDuration;
        unit.say("ARRRGH!!!");
    }
}

// The event handler for "collide" events.
function onCollide(event) {
    // The event owner who has collided with something.
    var unit = event.target;
    // The object the unit collided with.
    var collidedObject = event.other;
    // If it's a fence.
    if (collidedObject.type == "fence") {
        if (unit.scale == 2) {
            // Use the `destroy` method of collidedObject.
            unit.collidedObject(destroy);
        }
    }
}

// Assign onCollide to the "collide" event on the player.
player.on("collide", onCollide);
//# Assign onCollect to the "collect" event on the player.
player.on("collect", onCollect);

function checkTimers() {
    // If game time is greater than game.powerEndTime:
    if (game.time > game.powerEndTime) 
        if (game.scale == 2){
         game.PlayerScale(1);   
        }
        
    }
        // If player.scale is equal to 2: 
        
            // Set the player's scale to 1.
            


while (true) {
    checkTimers();
}

cool.

1 Like

Yes according to your code you haven’t defined game.PlayerScale. I haven’t done a lot of this recently so I’m not sure exactly how. You could look it up

But that’s what it’s telling me to say, how do I define it? is not saying it defining it? I also couldn’t find what else I was doing wrong. Thank you! :slight_smile:

Tbh I’m not sure @Falcons118 or @milton.jinich probably know as well as @Chaboi_3000

Don’t ask me I can’t even make a if statement in JS

Lol ok well someone knows just not me I don’t do Game Development

Change game.scale to player.scale and also change game.PlayerScale(1) to

player.scale = 1

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.