Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Please help me vital powers(Solved)

#1

here’s my hero:

jtg
and this is my code:

Этом уровень покажет, как определять собственные функции.

Код внутри функции не выполняется сразу. Он откладывается напото.

Эта функция заставляет вашего героя поднять ближайшую монету.

def pickUpNearestCoin():
items = self.findItems()
nearestCoin = self.findNearest(items)
if nearestCoin and self.distanceTo(nearestCoin)<30:
if self.isReady(“jump”):
self.jumpTo(nearestCoin.pos)
else:
self.move(nearestCoin.pos)

С помощью этой функции ваш герой призывает солдата.

def summonSoldier():
# Заполни код здесь, что призвать солдата, если у тебя достаточно золота.
if self.gold > self.costOf(“soldier”):
self.summon(“soldier”)

Эта функция приказывает вашим солдатам атаковать ближайшего враг.

def commandSoldiers():
for soldier in self.findFriends():
enemy = soldier.findNearestEnemy()
if enemy:
self.command(soldier, “attack”, enemy)
def attack(target):
if target:
if(self.isReady(“jump”) and self.distanceTo>10):
self.jumpTo(target.pos)
elif(self.isReady(“bash”)):
self.bash(target)
hero.attack(enemy)
else:
self.attack(target)
def tacktick():
enemies = self.findEnemies()
nearest = self.findNearest(enemies)
friends = self.findFriends()
if nearest and (self.distanceTo(nearest)<10 or self.now()>25):
attack(nearest)
elif nearest and len(friends)/3<len(enemies):
attack(nearest)
else:
pickUpNearestCoin()
while True:

# В своем цикле ты можешь "вызывать" функции, определенные выше.
# Эта строка вызывает выполнение кода внутри функции "pickUpNearestCoin" .
tacktick()
summonSoldier()
commandSoldiers()

But it wont work can anybody help please
kind regards
Sarah B :smiley::smiley::smiley::smiley::japanese_ogre::japanese_ogre::

#2

Please learn to post your code correctly. The way it is now, we can’t see the structure. Help us help you. It’s very easy to do and just takes a tiny bit of effort. Please read this topic and format your code again correctly

#3

ok thanks sorry @Chaboi_3000

#4
Этом уровень покажет, как определять собственные функции.
Код внутри функции не выполняется сразу. Он откладывается напото.
Эта функция заставляет вашего героя поднять ближайшую монету.
def pickUpNearestCoin():
items = self.findItems()
nearestCoin = self.findNearest(items)
if nearestCoin and self.distanceTo(nearestCoin)<30:
if self.isReady(“jump”):
self.jumpTo(nearestCoin.pos)
else:
self.move(nearestCoin.pos)

С помощью этой функции ваш герой призывает солдата.
def summonSoldier():
# Заполни код здесь, что призвать солдата, если у тебя достаточно золота.
if self.gold > self.costOf(“soldier”):
self.summon(“soldier”)

Эта функция приказывает вашим солдатам атаковать ближайшего враг.
def commandSoldiers():
for soldier in self.findFriends():
enemy = soldier.findNearestEnemy()
if enemy:
self.command(soldier, “attack”, enemy)
def attack(target):
if target:
if(self.isReady(“jump”) and self.distanceTo>10):
self.jumpTo(target.pos)
elif(self.isReady(“bash”)):
self.bash(target)
hero.attack(enemy)
else:
self.attack(target)
def tacktick():
enemies = self.findEnemies()
nearest = self.findNearest(enemies)
friends = self.findFriends()
if nearest and (self.distanceTo(nearest)<10 or self.now()>25):
attack(nearest)
elif nearest and len(friends)/3<len(enemies):
attack(nearest)
else:
pickUpNearestCoin()
while True:

# В своем цикле ты можешь "вызывать" функции, определенные выше.
# Эта строка вызывает выполнение кода внутри функции "pickUpNearestCoin" .
tacktick()
summonSoldier()
commandSoldiers()```
#5

heeeeeeeeeeeeeeelllllllllllllllllllllllllooooooooooooooooooooooooooooo (I don’t mean to be rude)
has anybody seen my posts!!!
kind regards
sarah

1 Like
#6

Did i do anything wrong? if so please tell me.
Kind regards
Sarah

1 Like
#7

You have to copy the code from the game, not from here. That’s why there’s no indents in your formatted code. Proper indents are critical. Yes, you have used the triple back ticks and that’s great, but you need to copy the code from the game.

2 Likes
#8

I straightened out your code and used it to pass - only made it 30 seconds and collected lots of gold but it did pass. There were many things I had to change. I’m going to PM the code to you. Go line by line to compare the changes in mine with what you have to understand the difference. Also, you need a faster sword. The one you’re using packs a big punch, but you need to swing faster against that many enemies. It doesn’t take much to kill them so you don’t need as much damage per swing, you just need to swing it faster.

def pickUpNearestCoin():
items = self.findItems()  # This looks for an array.  You can't move to array because it doesn't have a specific position.
nearestCoin = self.findNearest(items) # same as above.  Try a simple, item = self.findNearestItem().

if nearestCoin and self.distanceTo(nearestCoin)<30:  # Alter the remaining code to accommodate the variable changes above.
if self.isReady(“jump”):
self.jumpTo(nearestCoin.pos)
else:
self.move(nearestCoin.pos)
def attack(target):  # (The target argument is not necessary if you define target in the function)
# target = self.findNearestEnemy()
if target:
if(self.isReady(“jump”) and self.distanceTo>10):
self.jumpTo(target.pos)
elif(self.isReady(“bash”)):
self.bash(target)
hero.attack(enemy) # You have not defined enemy.  Did you mean target?
else:
self.attack(target)
def tacktick():  # I eliminated this function.  It's not necessary.  Just call the four other functions in a while True loop.
enemies = self.findEnemies()
nearest = self.findNearest(enemies)
friends = self.findFriends()
if nearest and (self.distanceTo(nearest)<10 or self.now()>25):
attack(nearest)
elif nearest and len(friends)/3<len(enemies):
attack(nearest)
else:
pickUpNearestCoin()
1 Like
#9

ok thanks which sword do you recommend?
kind regards
Sarah

#10

I only have the Simple Sword,Sharpened Sword,Long Sword and Kithsteel Blade but if you recommend one i dont have i can just save up and buy it.
kind regards
@MunkeyShynes

#11

Sorry it took so long to get back I was cooking some chicken and curry rice.
kind regards
sarah

#12

Sword of the Temple Guard is best if you can afford it. Fast and powerful.

1 Like
#13

OK thanks whew if only i knew that was the best one back when I had 5000 gems this is gonna be hard but thanks @MunkeyShynes

#14

You probably shoudn’t use the sword you have equipped in your screenshot. To my understanding and correct me if I am wrong, that sword requires more code than just the
hero.attack code that you would use. There are a few more lines of code you need to be able to use the full power that the sword contains

:fox_face::fox_face::fox_face:
@Luke10