[SOLVED] Keeping time JS

// Use your new skill to choose what to do: hero.time

function jumpTo(position) {
    if (hero.isReady("jump")) {
        hero.jumpTo(position);
        
    }
    else {
        hero.moveXY(position.pos.x, position.pos.y);
    }
}

while(true) {
    // If it's the first 10 seconds, attack.
    var enemy = hero.findNearestEnemy();
    if (hero.time < 10 || hero.time > 30) {
        if (hero.isReady("bash")) {
            hero.bash(enemy);
        }
        else if (hero.canCast("chain-lightning", enemy)) {
            hero.cast("chain-lightning", enemy);
        }
        else {
            hero.attack(enemy);
        }
    }
    // Else, if it's the first 35 seconds, collect coins.
    else if (hero.time <= 30) {
        var item = hero.findNearestItem();
        if (item) {
            jumpTo(item);
        }
    }
    // After 35 seconds, attack again!
}

hero keep attacking the group of big stronk ogre
and soldier keep getting killed

help. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

careful with this comment, you didn’t do anything about it

like this? if (hero.time < 10 || hero.time > 35) {

1 Like

how do i avoid hero to attack the palisade before collecting coin

// Use your new skill to choose what to do: hero.time

function jumpTo(position) {
    if (hero.isReady("jump")) {
        hero.jumpTo(position);
        
    }
    else {
        hero.moveXY(position.pos.x, position.pos.y);
    }
}

while(true) {
    // If it's the first 10 seconds, attack.
    var enemy = hero.findNearestEnemy();
    if (enemy && hero.time <= 10) {
        hero.attack(enemy);
    }
    
    // Else, if it's the first 35 seconds, collect coins.
    else if (hero.time <= 30) {
        var item = hero.findNearestItem();
        if (item) {
            jumpTo(item);
        }
    }
    else {
        var enemy = hero.findNearestEnemy();
        if (enemy && hero.time > 35) {
            hero.attack(enemy);
        }
    }
    // After 35 seconds, attack again!
}

Let me get this straight.
Do you want to collect your coins first and then attack the enemy?

yes 20 charrrrssssssss

When you say ( enemy && hero.time <= 10).
What you are writing is ( there is an enemy, and the time is between zero and ten seconds ( the equals sine includes ten) ).
Does this help?

so i must attack when times is 10?

if (self.time == 10) {
look it still attacking the fence
'// Use your new skill to choose what to do: hero.time

while(true) {
    // If it's the first 10 seconds, attack.
    if (hero.time < 10) {
        var enemy = hero.findNearestEnemy();
        hero.attack(enemy);
    }
    // Else, if it's the first 35 seconds, collect coins.
    else if (hero.time < 35) {
        var item = hero.findNearestItem();
        if (item) {
            hero.attack(enemy);
        }
    }
    // After 35 seconds, attack again!
    else {
        if (hero.time > 35) {
            var enemy = hero.findNearestEnemy();
            hero.attack(enemy);
        }
    }
}
'

@JWH ???

You wrote ( enemy && hero.time <= 10)
What you are writing is ( there is an enemy, and the time is less than or equal to ten).
So looking at the rest of your code, what will happen is when the time is less than ten, your hero will attack when the time is not less than ten but is less than 35 your hero will pick up coins when the time is greater than 35 he will attack the enemies again.

1 Like

heres new code. 20 chars

it working right after i use the cleave sword i don’t know why.

well thanks for helping

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