HELP PLEASE
Do you not remember how to use a while-loop? If you do not, replay Mad Maxer and Cloudrip Commander. Those levels should jog your memory.
Thatâs not the problem. the priblem is the âLine 19: tmp47[tmp48] is not a functionâ
Hm, thatâs no good. What glasses are you using?
Not the twilight i am using the fine wooden glasses. my bad
Ok now I am using the Twilight glasses and the error is fixed, but another popped up saying âHero Placeholder needs somthing to commandâ on line 26: self.command(âsoldierâ, âattackâ, enemy)
Can you post the entirety of your code?
To format your code correctly please press the </>
button in the Discourse toolbar or surround your code with 3 back ticks.
```
Code goes here.
```
# Gather coins to summon soldiers and have them attack the enemy
item = self.findNearestItem()
itemPos = item.pos
x = itemPos.x
y = itemPos.y
loop:
# Move to the nearest coin.
# Use move instead of moveXY so you can command constantly.
self.say("I need coins!")
self.moveXY(x, y)
# If you have funds for a soldier, summon one.
if self.gold > self.costOf("soldier"):
self.say("I should summon something here!")
self.summon("soldier")
enemy = self.findNearest(self.findEnemies())
if enemy:
# Loop over all your soldiers and order them to attack.
soldiers = self.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
# Use the 'attack' command to make your soldiers attack.
#self.command(soldier, "attack", enemy)
self.command(soldier, "attack", target)
You donât define target
. Do you mean âenemy
â?
# Gather coins to summon soldiers and have them attack the enemy
item = self.findNearestItem()
itemPos = item.pos
x = itemPos.x
y = itemPos.y
loop:
# Move to the nearest coin.
# Use move instead of moveXY so you can command constantly.
self.say("I need coins!")
self.moveXY(x, y)
# If you have funds for a soldier, summon one.
if self.gold > self.costOf("soldier"):
self.say("I should summon something here!")
self.summon("soldier")
enemy = self.findNearestEnemy()
if enemy:
# Loop over all your soldiers and order them to attack.
soldiers = self.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
# Use the 'attack' command to make your soldiers attack.
#self.command(soldier, "attack", enemy)
self.command(soldier, "attack", enemy)
I see a few problems. You define item
once, but not again, so your hero will only pick up the nearest coin once. Also, you command only the first soldier to do anything.
This is the line that has an error:
soldiers = self.findFriends()
I think its just that I have crap gear. I bought a short sword and made the code so I just attacked, but I still die. You should just give me like 2600 gems and I will be good
Itâs basically out of the question to give you gems. We want you to progress on your own. Hitting us up for gems isnât the best way to do this. You could always try simulating. Go here: http://codecombat.com/play/ladder/cavern-survival#simulate and hit the button that says âsimulateâ. You will get gems based upon how many you have done.
Out of curiosity, why are you wearing Wooden Glasses? You should have at least the Mahogany Glasses by nowâŚ
I prefer the wooden glasses so I can use nearest enemy/nearest item. But now that I know how to use the nearest and enemies code, I will be using the twilight glasses
# Gather coins to summon soldiers and have them attack the enemy
loop:
items = self.findItems()
item = self.findNearest(items)
itemPos = item.pos
x = itemPos.x
y = itemPos.y
# Move to the nearest coin.
# Use move instead of moveXY so you can command constantly.
self.moveXY(x, y)
# If you have funds for a soldier, summon one.
if self.gold > self.costOf("soldier"):
self.summon("soldier")
enemies = self.findEnemies()
enemy = self.findNearest(enemies)
if enemy:
# Loop over all your soldiers and order them to attack.
soldiers = self.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
# Use the 'attack' command to make your soldiers attack.
#self.command(soldier, "attack", enemy)
self.command(soldier, "attack", enemy)
Now the problem is self.command(soldier, "attack", enemy)
It says: âHero Placeholder needs something to commandâ
soldiers is a indexed list.
It will contain the several values: soldiers[0], soldiers[1], soldiers[2], âŚ
The length of the list is given by len(soldiers)
Since the index numbers start from 0, the last index will be len(soliders)-1
Example:
mylist = [5,6,7]
# the length of this list is len(mylist) = 3
# the elements are mylist[0] = 5, mylist[1] =6, mylist[2] =7
Now knowing all this you can write:
soldierIndex=0
while (soldierIndex < len(soldiers)):
# do something with soldiers[soldierIndex]
soldierIndex++
A faster way to write the same loop:
for i in range(len(soldiers)):
# do something with soldiers[i]
The for structure automatically makes i go from 0 to len(soldiers)-1
Even faster
for soldier in soldiers:
#do something with solider
Instead of complicating with the index, this for makes solider go from soliders[0] to soldiers[len(soldiers)-1]
# Gather coins to summon soldiers and have them attack the enemy
loop:
items = self.findItems()
item = self.findNearest(items)
itemPos = item.pos
x = itemPos.x
y = itemPos.y
# Move to the nearest coin.
# Use move instead of moveXY so you can command constantly.
self.moveXY(x, y)
# If you have funds for a soldier, summon one.
if self.gold > self.costOf("soldier"):
self.summon("soldier")
enemies = self.findEnemies()
enemy = self.findNearest(enemies)
if enemy:
# Loop over all your soldiers and order them to attack.
soldiers = self.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
# Use the 'attack' command to make your soldiers attack.
#self.command(soldier, "attack", enemy)
self.command(soldier, "attack", enemy)
OK This is my code. Everything works but my soldiers donât attack
The code hint says:
# Loop over all your soldiers and order them to attack.
Look at my post above. No spoonfeeding
# Gather coins to summon soldiers and have them attack the enemy
loop:
items = self.findItems()
item = self.findNearest(items)
itemPos = item.pos
x = itemPos.x
y = itemPos.y
# Move to the nearest coin.
# Use move instead of moveXY so you can command constantly.
self.moveXY(x, y)
# If you have funds for a soldier, summon one.
if self.gold > self.costOf("soldier"):
self.summon("soldier")
enemies = self.findEnemies()
enemy = self.findNearest(enemies)
if enemy:
# Loop over all your soldiers and order them to attack.
soldiers = self.findFriends()
soldierIndex += 1
soldier = soldiers[soldierIndex]
soldierIndex += 1
myList = [5, 6, 7]
# Use the 'attack' command to make your soldiers attack.
#self.command(soldier, "attack", enemy)
for soldier in soldiers:
self.command(soldier, "attack", enemy)
Is this right? Because it still doesnât work