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

**URL:** <https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053>\
**Category:** Processing.py\
**Created:** [December 31, 2018, 12:04pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053 "2018-12-31T12:04:50Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [December 31, 2018, 12:04pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/1 "2018-12-31T12:04:51Z")

</div>

```auto
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)

```

```auto
def addtail(self,x,y):
        self.prevs.append(PVector(x,y))

```

```auto
#...........
 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! 🎆🎆

---

<div class="post-metadata">

**Author:** ![TheWizardBear](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thewizardbear/32/3552_2.png) [@TheWizardBear](https://discourse.processing.org/u/TheWizardBear)\
**Post date:** [December 31, 2018, 4:28pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/2 "2018-12-31T16:28:45Z")

</div>

Is this

> [@Sky](#):
>
> ```auto
> for num in range(0,len(self.prevs)):
> fill(255,0,0)
> rect(self.prevs[num].x,self.prevs[num].y,22,22)          
> 
> ```

part of the addtail() function?

---

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [December 31, 2018, 4:30pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/3 "2018-12-31T16:30:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TheWizardBear](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thewizardbear/32/3552_2.png) [@TheWizardBear](https://discourse.processing.org/u/TheWizardBear)\
**Post date:** [December 31, 2018, 4:31pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/4 "2018-12-31T16:31:42Z")

</div>

What line is it saying the error is coming from?

---

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [December 31, 2018, 4:32pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/5 "2018-12-31T16:32:28Z")

</div>

> [@Sky](#):
>
> rect(self.prevs[num].x,self.prevs[num].y,22,22)

this line. I dont know why

---

<div class="post-metadata">

**Author:** ![TheWizardBear](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thewizardbear/32/3552_2.png) [@TheWizardBear](https://discourse.processing.org/u/TheWizardBear)\
**Post date:** [December 31, 2018, 4:33pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/6 "2018-12-31T16:33:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [December 31, 2018, 4:37pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/8 "2018-12-31T16:37:40Z")

</div>

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

```auto
 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[]

```

---

<div class="post-metadata">

**Author:** ![TheWizardBear](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thewizardbear/32/3552_2.png) [@TheWizardBear](https://discourse.processing.org/u/TheWizardBear)\
**Post date:** [December 31, 2018, 4:41pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/9 "2018-12-31T16:41:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [December 31, 2018, 4:43pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/10 "2018-12-31T16:43:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TheWizardBear](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thewizardbear/32/3552_2.png) [@TheWizardBear](https://discourse.processing.org/u/TheWizardBear)\
**Post date:** [December 31, 2018, 4:45pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/11 "2018-12-31T16:45:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [December 31, 2018, 4:46pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/12 "2018-12-31T16:46:58Z")

</div>

```auto
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

---

<div class="post-metadata">

**Author:** ![TheWizardBear](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thewizardbear/32/3552_2.png) [@TheWizardBear](https://discourse.processing.org/u/TheWizardBear)\
**Post date:** [December 31, 2018, 4:48pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/13 "2018-12-31T16:48:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [December 31, 2018, 4:49pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/14 "2018-12-31T16:49:27Z")

</div>

OMG my mistake, self.prevs is the actaully tail  
😊

---

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [December 31, 2018, 4:51pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/16 "2018-12-31T16:51:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TheWizardBear](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thewizardbear/32/3552_2.png) [@TheWizardBear](https://discourse.processing.org/u/TheWizardBear)\
**Post date:** [December 31, 2018, 4:53pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/17 "2018-12-31T16:53:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [December 31, 2018, 4:54pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/18 "2018-12-31T16:54:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [December 31, 2018, 4:54pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/19 "2018-12-31T16:54:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TheWizardBear](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thewizardbear/32/3552_2.png) [@TheWizardBear](https://discourse.processing.org/u/TheWizardBear)\
**Post date:** [December 31, 2018, 4:55pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/20 "2018-12-31T16:55:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [December 31, 2018, 4:57pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/21 "2018-12-31T16:57:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [December 31, 2018, 4:57pm UTC](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053/22 "2018-12-31T16:57:20Z")

</div>

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

[Next page](https://discourse.processing.org/t/garbage-game-list-has-no-attribute-x-or-y/7053.md?page=2)
