I am on the Greed Traps map and for some reason the map isn’t working properly.
This is the initial instructions filled out with exactly what the developer asked the user to input:
# Patrol and place traps ONLY if you see a coin.
# Write this function.
def maybeBuildTrap(x, y):
# Move to the given x,y postion
hero.moveXY(x, y)
# Search a coin and if you see it, build a "fire-trap"
item = hero.findItems()
if item == "coin":
hero.buildTypes("fire-trap", x, y)
pass
while True:
# Call maybeBuildTrap for the top left passage.
maybeBuildTrap(12, 56)
# Now for the top right passage.
maybeBuildTrap(68, 56)
# Now for the bottom right passage.
maybeBuildTrap(68, 12)
# Now for the bottom left passage.
maybeBuildTrap(12, 12)
Now, I run the script and the hero does move to every X without difficulty. However, he does not detect items nor does he lay down fire-traps. I have tried to modify my code to make this map work properly but I am a novice programmer at best. Maybe one of you more experienced users can figure this out or assist me in figuring out a solution to this problem. Thanks for the assist
Thanks for the response Deadpool198. I actually just solved it. Appreciate you taking the time to respond. I understand what I did wrong. First, I labeled the build type wrong
You were correct to switch from hero.findItems to findNearestItem - findItems is used to find arrays, not individual items.
The problem is in your function. You define item and then check to see if item is a coin, but never look to see if item exists. Since the only items you’ll find in this level are coins, there’s really no need to check for the item type. Try just using, if item: instead.
lol, no worries. I really appreciate the responses. This is my first attempt at coding so I will probably be posting help requests in the forum several times a week. Look forward to picking your brain more
# Patrol and place traps ONLY if you see a coin.
# Write this function.
def maybeBuildTrap(x, y):
# Move to the given x,y postion
hero.moveXY(x, y)
item = hero.findNearestItem()
if item:
if item.type == "coin":
hero.buildXY("fire-trap", x, y)
# Search a coin and if you see it, build a "fire-trap"
pass
while True:
# Call maybeBuildTrap for the top left passage.
maybeBuildTrap(12, 56)
# Now for the top right passage.
maybeBuildTrap(68, 56)
# Now for the bottom right passage.
maybeBuildTrap(68, 12)
# Now for the bottom left passage.
maybeBuildTrap(12, 12)
For some reason the character just goes on walking in a rectangle shape but ignores coins, therefore forgetting to build traps! Some coins do not even appear!