Accounts Department


#1

I can’t tell whats wrong with this code, nothing spawned like it was supposed to?!?

// Count collected item values and use them for scoring.

// Setup characters.
var hero = game.spawnHeroXY(“captain”, 40, 34);
hero.maxSpeed = 20;
var generator1 = game.spawnXY(“generator”, 4, 34);
var generator2 = game.spawnXY(“generator”, 76, 34);
generator1.spawnDelay = 7;
generator2.spawnDelay = 7;

// Chests of gems are the most valuable items.
game.spawnXY(“chest”, 68, 56);
game.spawnXY(“chest”, 14, 14);

// This function spawns a random item in a random place.
function spawnRandomItem() {
var itemNumber = game.randomInteger(1, 3);
var x = game.randomInteger(12, 68);
var y = game.randomInteger(12, 56);
if (itemNumber == 1) {
game.spawnXY(“bronze-coin”, x, y);
}
else if (itemNumber == 2) {
game.spawnXY(“gold-coin”, x, y);
}
else if (itemNumber == 3) {
game.spawnXY(“gem”, x, y);
}
}

var itemInterval = 1;
var itemSpawnTime = 0;
function checkSpawnTimer() {
if (game.time >= itemSpawnTime) {
spawnRandomItem();
itemSpawnTime += itemInterval;
}
}

game.score = 0;

// The “collect” event is triggered by collecting something.
function onCollect(event) {
// event.target contains the collector.
var collector = event.target;
// event.other contains the collected item.
var item = event.other;
if (item.value) {
// Increase the game score by the item’s value:
game.score =+ item.value;
}
}

// Assigning onCollect handler for “hero” on “collect” event.
hero.on(“collect”, onCollect);

// Setup the goals and UI.
var endTime = 20;
// The score the player needs to win.
var requiredScore = 220;
var goldGoal = game.addManualGoal(‘Collect at least 220 gold in 20 seconds.’);
ui.track(game, “score”);
ui.track(game, “time”);

function checkGoals() {
if (game.time >= endTime) {
// If game score is greater or equal to requiredScore
if (game.score => requiredScore)
goldGoal.success = true;
// Else goldGoal has failed:
} else {
goldGoal.success = false;
}
}

while(true) {
checkSpawnTimer();
checkGoals();
}


#2

Please learn to post your code properly.

To post your code from the game, use the </> button or it won’t format properly. When you click the </> button, the following will appear:

Please paste ALL of your code inside the triple back tick marks.

``` <— Triple back tick marks.

Paste ALL of your code in here.

``` <— Triple back tick marks.

There are many people here willing and able to help. If you use the </> button correctly, then ALL of your code should look like this:

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
    else:
        hero.say("My code is formatted properly")

If ALL of your code isn’t formatted like the code above, then you’re doing it wrong and we can’t see the structure of the code to troubleshoot whether or not that is the issue. Use the </> button and help us help you. This works when sending a private message as well.

Thank you.


#3

From what I could see you didn’t define checkGoals();


#4