// Użyj funkcji checkAndAttack by uprościć swój kod.
// Ta funkcja ma parametr. // Parametr to sposób na przekazanie informacji do funkcji. function checkAndAttack(target) { // Parametr 'target' jest tylko zmienną! // Zawiera argument ,gdy funkcja zostanie wywołana. if(target) { hero.attack(target); } hero.moveXY(43, 34); }
// Define your own function to fight the enemy! function cleaveOrAttack() { // In the function, find an enemy, then cleave or attack it. var ogre = hero.findNearestEnemy(); if (ogre) { if (hero.isReady("cleave")) { hero.cleave(ogre); } // Else attack the ogre: else { hero.attack(ogre); } } }
# Użyj funkcji checkAndAttack by uprościć swój kod.
# Ta funkcja ma parametr. # Parametr to sposób na przekazanie informacji do funkcji. def checkAndAttack(target): # Parametr 'target' jest tylko zmienną! # Zawiera argument ,gdy funkcja zostanie wywołana. if target: hero.attack(target) hero.moveXY(43, 34)
while(true) { var enemy = hero.findNearestEnemy(); if(enemy) { // Find the distance to the enemy with distanceTo. var distance = hero.distanceTo(enemy); // If the distance is less than 5 meters... if(distance < 5) {
while(true) { var enemy = hero.findNearestEnemy(); if(enemy) { // Find the distance to the enemy with distanceTo. var distance = hero.distanceTo(enemy); // If the distance is less than 5 meters... if (distance < 5) {
// You can put one if-statement within another if-statement. // Be careful how the if statements interact with each other. // It's helpful to start with one outer if/else, // using comments as placeholders for the inner if/else:
while(true) { var enemy = hero.findNearestEnemy(); // If there is an enemy, then... if(enemy) { // Create a distance variable with distanceTo. var distance = this.distanceTo(enemy); // If the distance is less than 5 meters, then attack. if(distance < 5){ this.attack(enemy); }