Hunters and Prey serious bug

For the level Hunters and Prey in Cloudrip Mountain the sample code is in Javascript while I use Python. When I put a python code my whole code ends up being wrong. Does anyone have any solutions???

press reload on the top right corner

I already tried but it still ends up in Javascript.

did go to hero and check if its python

I did and it shows that I am using python. This is my code:

# Ogres are trying to kill your reindeer!
# Keep your archers back while summoning soldiers to attack.

def pickUpCoin():
    coin = self.findNearest(self.findItems())
    if coin:
        self.move(coin.pos)
    pass

def summonTroops():
    if self.gold > self.costOf("soldier"):
        self.summon("soldier")
    # Summon soldiers if you have the gold.
    
    pass
    
# This function has an argument named soldier.
# Arguments are like variables.
# The value of an argument is determined when the function is called.
def commandSoldier(soldier):
    enemy = soldier.findNearestEnemy
   if enemy:
        self.command(soldier, "attack", enemy)
    # Soldiers should attack enemies.
    pass

# Write a commandArcher function to tell your archers what to do!
# It should take one argument that will represent the archer passed to the function when it's called.
# Archers should only attack enemies who are closer than 25 meters, otherwise, stay still.
def commandarcher(archer):
    enemy = archer.findNearest(archer.findenemies)
    if enemy and archer.distanceTo(enemy) < 25:
        self.command(archer, "attack", enemy)
    else:
        self.command(archer, "move", archer.pos)
loop:
    pickUpCoin()
    summonTroops()
    friends = self.findFriends()
    for friend in friends:
        if friend.type == "soldier":
            # This friend will be assigned to the variable soldier in commandSoldier
            commandSoldier(friend)
        elif friend.type == "archer":
            commandarcher(friend)

mabye you should ask nick if you think this is a glitch

I have invited him and am waiting for him to come.

so you did @ and then nick

@nick Please help me Out!!!

What’s your CodeCombat username? I’ll check it out. It sounds like if you go to the hero selection screen and pick both a different hero and a different programming language, you might be able to switch it back to Python.

It is DarkShadow66!!!

If nothing works @nick can someone just translate this to Javascript and give me the translated code!Thx
My code:

loop:
    coin = self.findNearest(self.findItems())
    enemy = self.findNearest(self.findEnemies())
    friends = self.findFriends()    
    if coin:
        self.move(coin.pos)
        if self.gold >=20:
            self.summon("soldier")
            
            for friend in friends:
                if friend.type is "soldier":
                    self.command(friend, "move", {'x':25, 'y':70})
                    
        elif enemy:
            if friends:
                for friend in friends:
                    if friend.type is "soldier":
                        self.command(friend, "attack", enemy)
            for friend in friends:
                if friend.type is "archer":
                    self.command(friend, "move", {'x':25, 'y':25})
                    
        elif enemy:
            if friends:
                for friend in friends:
                    if friend.type is "archer":
                        self.command(friend, "attack", enemy)

I need a answer in at least 2 days because I am falling behind everyone in my class!

wait i thought you just said you were using python

try exploiting it for now i found a exploit by accident and the ogre attacked the soldiers instead

so i built summoned archers around the deers and the ogres did not spawn around them because they cant spawn near archer (summon not build and dont command)

All I need is someone to translate my code to JavaScript

How to translate the code into javascript:

  1. put β€œ;” after each instruction. If you forget, the compiler will tell you to do it EASY.
  2. put a β€œvar” to declare the variable each time you write a new variable. If you put too many var or not enough the compiler will tell you EASY
friends = self.findFriends()

becomes:

var friends = self.findFriends();
  1. Put the if or for in the parentheses
  2. Remove the β€œ:” after if or for
  3. Put brackets β€œ{” around the instructions inside the if or for
    DIFFICULTY: STRAIGHT FORWARD
if friends:
    for friend in friends:
         if friend.type is "soldier":
               self.command(friend, "attack", enemy)

becomes

if (friends){
    for (friend in friends){
        if (friend.type is "soldier"){
             self.command(friend, "attack", enemy);
        }
    }
}
  1. Inside the β€œif” argument python uses β€œis” for equal, β€œnot” for negation,
    β€œis not” for not equal. Javascript uses β€œ==”, β€œ!” and "!="
    DIFFICULTY: EASY
Python          JavaScript
is                ==
not               !
is not            != 

so

if friend.type is "archer":

becomes:

if (friend.type == "archer"){
  1. In JavaScript the for in works different: it will give you the index of
    an element instead of the object element.
    You need to add this line immediately after the for:
friend=friends[i];

DIFFICULTY: YOU"LL FIGURE IT OUT

for friend in friends:
     if friend.type is "archer":
         self.command(friend, "attack", enemy)

becomes:

for (i in friends){
     friend=friends[i];
     if (friend.type == "archer"){
         self.command(friend, "attack", enemy);
     }
}
  1. Replace all self with this
self.command(friend, "attack", enemy)

becomes

this.command(friend, "attack", enemy);

Congratulations, you have now learned how to program in JavaScript !!

  1. Learn to program in both Python and Javascript, ask your schoolmates for help. Do not rely on code copied from internet.
    DIFFICULTY: HARD BUT WORTH IT.
1 Like

You know what my mind is getting messed up because I have many problems going on. So can someone just send me the translated code in my gmail!!Thx
PLEASE PLEASE PLEASE PLEASE
My gmail:
crummyface126@gmail.com