I have two question of metal detector
- In picture 1, the code search coin by item.type==“coin”, but system sign type error.
- In picture 1, the code search coin of distance by “distance = hero.distanceTo(item)”, but system sign argument error.
I can’t tell the difference between picture 1 and picture 2
The picture 1 is my original answer
The picture 2 is my revised answer
Welcome to the forum @greedy0101! This is a friendly place where you can ask help on levels, report bugs, or just chat with other coders! Don’t forget to read the guidelines if you haven’t yet. Have a great time!
In the first picture, you defined item, then you tried to find the distance to the item. Below that, you have an if-statement that checks the type of the item. We should take into consideration that the item isn’t necessarily existing, so item might be null, which will give you an error if it’s null.
In the second picture, you made sure the item exists, then you got the distance of the existing item, which eliminated the error. Hope this explains it. If it doesn’t you can ask for more clarification
PS: Please for the next time, put your code as text and formatted as well as it is easier to point out the problem
you should probably do no
else: return 0 , because wouldn’t the artillery blow itself up?