My code is this:
# This level shows how to define your own functions.
# The code inside a function is not executed immediately. It's saved for later.
# This function has your hero collect the nearest coin.
# This function has your hero summon a soldier.
def summonSoldier():
# Fill in code here to summon a soldier if you have enough gold
if self.gold >= self.costOf("soldier"):
self.summon("soldier")
else:
break
# This function commands your soldiers to attack their nearest enemy.
def commandSoldiers():
soldiers = self.findFriends()
if soldiers:
for soldier in self.findFriends():
target = soldier.findNearest(soldier.findEnemies())
if target:
self.command(soldier, "attack", target)
def pickUpNearestCoin():
while self.gold < self.costOf("soldier"):
coin = self.findNearest(self.findItems())
self.moveXY(coin.pos.x, coin.pos.y)
loop:
# In your loop, you can "call" the functions defined above.
# The following line causes the code inside the "pickUpNearestCoin" function to be executed.
pickUpNearestCoin()
# Call summonSoldier here
summonSoldier()
#Call commandSoldiers here
commandSoldiers()
I get an error on, “if target” (line 17), which is the most ANNOYING of them all, “Attempted to assign readonly property.” The reason it is so annoying? I don’t even know what it means and how to fix it!
Even before I started getting this error, Tharin wouldn’t move after getting coins and summoning his first soldier. Besides the obvious gear (Boss Star, Progammaticon IV), I have:
Kithsteel Blade,
Emperor’s Glove (yeah, that’s right),
Simple Wristwatch,
Trap Belt,
Crude Telephoto Glasses,
Quartz Sense Stone,
Basic Flags,
Steel Ring,
Defensive Boots,
Rusted Iron Breastplate,
Rusted Iron Helmet,
and the Steel Striker.
What should I do?
You have a break
in your summonSoldier()
function, which could possibly break you out of your loop when you don’t have enough gold.
Ok, I’ll see if it’ll make it work.
Also, do you think my gear is good enough?
Well, it fixed the error and the stopping after getting my first soldier, and I commanded them, but I still died.
I added chain-lightning to get coin, so now pickUpNearestCoin() is:
def pickUpNearestCoin():
while self.gold < self.costOf("soldier"):
coin = self.findNearest(self.findItems())
self.moveXY(coin.pos.x, coin.pos.y)
enemies = self.findEnemies()
enemy = self.findNearest(enemies)
if enemy and self.canCast("chain-lightning", enemy):
enemy = self.findNearest(enemies)
self.cast("chain-lightning", enemy)
Yes, I know that variable declaration is the way you do it for JavaScript, but I started JavaScript after Python on Codecademy and then halted my Python, so yeah, I’m used to declaring variable names in JavaScript.
Also, still dying.
Should I add more ways to attack? And/or get The Precious and use it?
Use move
, not moveXY
. It will actually collect coins slightly faster, and that could be you key to victory.
I’ll try that now! I’m not sure if it’ll work, since I’m not close at all! But it will contribute!
Died but a LOT closer! Then added bashing and attack after chain-lightning add-on to be done IF enemy and isReady and (for the latter) distanceTo enemy < attackRange (that’s not the EXACT code, obviously), and got even closer. I’m about to try it with cleave and Long Sword(?).
Ok, both with cleave and without it got me past 30 seconds!!! THX!
However, I didn’t get the gold. Does the remaining gold have to be >= 125 at the end, or can it be spent and just the spent gold and remaining gold added together be >= 125?
The total gold you have collected has to be greater than or equal to 125.
So, as in, altogether, including the gold I’ve spent? Ok.
How do I work on the gold part? Stop other stuff after 30 seconds and focus on the gold more?
Summoning a unit only takes one frame, so it won’t slow you down enough to matter. Do you have the Ring of Speed, or the means to purchase it, or perhaps the Precious? Those could make the difference.
Not enough gems for me, I will get some.