Backwoods forest:Wizard's Door noob help


#1

I feel like I am lacking a very fundamental knowledge on how to convert these named “targets” into something the function can recognize(?). I have never taken a coding class before so i apologize if im using these terms poorly. Thank you!

ERROR:
Line 3: cannot read property ‘x’ of undefined

What I’m trying to do:
Find out coordinates of “friend”(Laszlo)>go to friend>get the secret>go to another named “friend”(Erzsebet)

The suggested solution since im literally a noob is

hero.moveXY(30, 13)

However, i highly dislike typing out coordinates if at all possible, i’ve been stuck on this for the past 3 hours and would really appreciate any help. Thank you!

My attempts:
Cannot read property ‘x’ of undefined

friend = "Laszlo"
friendpos = friend.pos        
fx = friendpos.x
fy = friendpos.y
hero.moveXY(fx, fy)

ERROR: findNearestFriend takes no arguments.

friend = hero.findNearestFriend("Laszlo")
friendpos = friend.pos        
fx = friendpos.x
fy = friendpos.y
hero.moveXY(fx, fy)

THIS WORKS but i can’t use this same code to make it go to the next friend, Erzsebet

friend = hero.findNearestFriend()
friendpos = friend.pos        
fx = friendpos.x
fy = friendpos.y
hero.moveXY(fx, fy)

I know this is probably trivial for many of you but any help would be appreciated. Thank you!


#2

In this code you are just saying that the variable friend is some (String) or text.
It doesn’t contain the object friend.
so when you say to go to pos there is no coordinates.

friend = "Laszlo"
friendpos = friend.pos        
fx = friendpos.x
fy = friendpos.y
hero.moveXY(fx, fy)

in this code you are calling the function hero.findNearestFriend() that function take no arguments. An argument is when you have to specify an object or a value inside the function.

for example when you say hero.attack(enemy) Enemy is an argument inside the function. And this function can’t work without an argument.

friend = hero.findNearestFriend()
friendpos = friend.pos        
fx = friendpos.x
fy = friendpos.y
hero.moveXY(fx, fy)

the only way to find the position of every of your friends is with a list/array.
(the function to make a list of your friends is hero.findFriends()

It might be a bit too early to learn that as you are starting out. not sure if you can use arrays a this point either. I would tell you to learn slowly and go back to this level once you know how to do this.

Edit: the move(target.pos) function might maybe work I’ll test it later. (not MoveXY)


#3

Oh my god. Its 5am here now and i haven’t been able to sleep because of this. Thank you so much for the reply. I’ll keep advancing and will keep what you’ve taught me in mind.

Thank you!

Would you happen to have a source for me where I can read up on how strings and arguments work? or any source where i can learn the basics of python in general.


#4

http://files.codecombat.com/docs/resources/Course1PythonSyntaxGuide.pdf

I think you can start with that!


#5

Woah. That is actually what I’ve been looking for. Thank you!!!