Backwoods forest LVL- Multi player treasure groves. Bad code, bug, or feature?


#1

I am a noob in this coding world, so I may be coding totally wrong. But, in case I am not, perhaps I have come across coding bug?

As I try to set the values of X and Y for my variable for “picking up items,” specifically coins, I get an error message telling me my “undefined is not an object.” However, this is the same technique demonstrated on the video tutorial, so I am very confused and a bit frustrated as to why this code is not working.

Any feedback would be most appreciated.

ps: i have written the x and y value lower case not upper case as shown in the pic, if that is in any case a factor to the problem.

Thanks!

Here is the pic…


#2

Hah…just posted the same thing ten minutes after you. Using JS though, glad to see it’s happening across the board :stuck_out_tongue:

Hope we find a solution.


#3

ItemX = item.pos.x

& not
ItemX = itemPos.x

&
ItemX = itemPos.pos.x should also work I think


#5

im sorry what is JS?


#6

hey thanks for your reply,
i updated the code with itemX= item.Pos.x to no avail!

hmmm…


#7

ItemPos is a user defined variable. In python capital letters do matter. So, x & X are different.

POS and Pos are different.

But note that in codecombat, .pos is a pre-defined function. So better avoid confusing names.

I have not tested whether .POS or .Pos works just like .pos

Perhaps you can try and let us know if it works or not.

Also, item.pos actually returns both x and y coordinate. We define such positions like : {“x”: 34, “y”: 72}

to extract x part from item.pos we do item.pos.x

Similarly for y part.

JS - Java Script I think


#8

try small p.

item.pos.x

and not item.Pos.x


#9

If item.pos.x works and item.Pos.x doesn’t, it shows the importance of caps/case


#10

great!

i will talk in very laymen terms because i do not know or conceptualize code efficiently yet.

i want the character to move around the screen and automatically collect the coins as per the direction of where i plant the flag.

i have tried updating the code with lower case letters as in, “itemx = item.pos.x” and it does not work.

the reason i stated it may be a bug because, it worked about an hour ago. i copied the code for which the tutorial stated for that level which i believe was “drop the flag.”

ok i just went back to level, “Copper Meadows,” and in this level the code is the one you described as just

position = item.pos
x = position.x
y= postion.y
self.moveXY(x,y)

i guess i was confused between using the variable
position = item.pos (as shown above in the pic)

      VS   

itemPos= item.pos
(shown below in the pic)

didn’t think that the way i wrote would affect the outcome (automatically picking up the items)

i will try with your original suggestion " if item:
postion = item.pos
etc…


#11

part of my code (getting success, tried the level right now):

    item = self.findNearest(self.findItems())
    if item:
        self.moveXY(item.pos.x, item.pos.y)

Notice the compactness, all positions need not be defined. They can directly be formulated in the self.moveXY line


#12

jejeje thanks, that looks a bit like a shortcut, though effective i am still confused as to why my two versions of the code did not work… hmm ill do more reading tonight.

thanks for your feedback!