[garbage][🐍 game]List has no attribute X (or Y)

if dist(snake.vec.x,snake.vec.y,fruit.vec.x,fruit.vec.y) < 12.5:
         fruit.respawn()
         snake.score += 1
         snake.addtail(snake.vec.x,snake.vec.y)
def addtail(self,x,y):
        self.prevs.append(PVector(x,y))
#...........
 for num in range(0,len(self.prevs)):
            fill(255,0,0)
            rect(self.prevs[num].x,self.prevs[num].y,22,22)   
#..........       

(I know this code for adding a tail is wrong)
This is the only append(PVector(x,y)) that I have in my program,
but it says “List obj has no attribute x” (for the y is the same), only when I append a second PVector.
It works for the first tail, but when I add the secon tail, I get this error.

Happy New Year! :fireworks::fireworks:

Is this

part of the addtail() function?

o right, this is in the show function where I show head and tail

What line is it saying the error is coming from?

this line. I dont know why

Is the show function called after addTail() or before?

OK, addtail is called after show if i collected a fruit

 snake.keyPressed()
    snake.logic()
    prevH = snake.vec
    fruit.Show()
    snake.Show()
    if dist(snake.vec.x,snake.vec.y,fruit.vec.x,fruit.vec.y) < 12.5:
         fruit.respawn()
         snake.score += 1
         #i currently remved addtail but it was here
       #  snake.tail.append[]

Does snake.prevs start off empty (before any fruit is collected)?

yes, and after collecting a fruit I append one PVector
Now I dont have the old code, but its strange as error

Ok, can I see the whole show function for the snake and also where self.prevs is initially declared?

class Snake:
    def __init__(self):
        self.step = 25
        self.vec = PVector(float((500>>1) + (self.step>>1)),float((500>>1) + (self.step>>1)))
        self.score = 0
        self.tail = []
        self.dir = "STOP"
 def Show(self):
        fill(255)     
        rect(self.vec.x,self.vec.y,25,25)
        fill(255,0,0)
        textSize(20)
        text(self.score,self.vec.x-6.25,self.vec.y+6.25)
        fill(0)    
        for i in range(0,len(self.tail)):
            rect(self.tail[i].x,self.tail[i].y,22,22)                    

This should be the code when i got this error

I don’t think self.prevs is ever declared!

OMG my mistake, self.prevs is the actaully tail
:blush:

non i want to say that i changed name from self.prevs in sefl.tail,
old code: self.prevs, new code : self.tail
But this error is not a problem, now I dont have it anymore

So everywhere is says self.prevs, it is supposed to be self.tail?
(And it still doesn’t work?)

If u want you I can open a new topic and u can help me with the tails that spawns on my head,

Yes, but this problem is gone bc i changed all the code

So you’re basically saying, you fixed one problem but there is still another?

I am saying, the problem disappeared, and idk how.
THe second problem is just if you want to help, or I will continue by myself, bc i translated a code from a c++ ASCII snake (that did last year) to python, but I have this problem with the tails

I wonder why all your Python code posts so far haven’t been properly indented… :confused: