0
import pyglet

class CarMap:
  def __init__(self):
      self.in_map = [341, 161, 452, 121, 567, 123, 650, 160, 678, 241, 613, 340, 654, 467, 611, 508, 506, 514, 416, 437,
               289, 401, 207, 431, 130, 469, 110, 424, 128, 320, 157, 229, 95, 99, 217, 87]
      self.out_map = [344, 89, 445, 45, 572, 59, 691, 92, 756, 229, 695, 333, 715, 482, 649, 566, 455, 567, 409, 502, 319,
                476, 214, 492, 125, 550, 78, 557, 45, 485, 41, 353, 87, 254, 38, 88, 74, 35, 271, 44, 295, 70]
      self.score_lines = [341, 161,344, 89,567, 123,572, 59,678, 241,756, 229,654, 467,715, 482,506, 514,455, 567,130, 469,125, 550,157, 229,87, 254,95, 99,74, 35]
      #self.score_lines = [654, 467,715, 482,506, 514,455, 567,416,437,409,502,289,401,319,476,207,431,214,492,130, 469,125, 550,157, 229,87, 254,95, 99,74, 35]
      self.in_batch = pyglet.graphics.Batch()
      self.out_batch = pyglet.graphics.Batch()
      self.in_grey = float[160] * (len(self.in_map) / 2)
      self.out_grey = float[160] * (len(self.out_map) / 2)
      self.blue1 = [0, 39, 102,1]*(len(self.score_lines)/2)
      self.blue2 = [0, 97, 255, 1] * (2)
      self.in_batch.add(len(self.in_map) / 2, pyglet.gl.GL_LINE_LOOP, None, ('v2i', self.in_map),
                  ('c4B', self.in_grey * 4))
      self.out_batch.add(len(self.out_map) / 2, pyglet.gl.GL_LINE_LOOP, None, ('v2i', self.out_map),
                   ('c4B', self.out_grey * 4))

  def draw(self,score_activate):
        self.in_batch.draw()
        self.out_batch.draw()
        score_batch = pyglet.graphics.Batch()
        score_batch.add(16,pyglet.gl.GL_LINES,None,('v2i',self.score_lines),('c4B',self.blue1))
        score_batch.draw()
        score_batch2 = pyglet.graphics.Batch()
        score_batch2.add(2, pyglet.gl.GL_LINES, None, ('v2i', self.score_points(score_activate)), ('c4B', self.blue2))
        score_batch2.draw()


  def score_points(self,score_activate):
      if score_activate == 7:
         score_activate = -1
         return self.score_lines[score_activate*4+4:score_activate*4+8]

I got this error: "'type' object is not a subscriptable error" from the following lines of code.

self.in_grey = float[160] * (len(self.in_map) / 2)
self.out_grey = float[160] * (len(self.out_map) / 2)
JamCon
  • 2,313
  • 2
  • 25
  • 34
abc
  • 33
  • 1
  • 1
  • 9
  • 1
    What is `float[160]` supposed to be doing? – hpaulj Mar 02 '19 at 16:27
  • Could you add more context to what you are trying to do? – Teddy Mar 02 '19 at 16:30
  • 1
    Did you mean `float(160)`, and if so, why not just write `160.0`? – chepner Mar 02 '19 at 16:42
  • 1
    I believe with this line `self.in_grey = float[160] * (len(self.in_map) / 2)` you are trying to create a list containing 160.0 this many times `(len(self.in_map) / 2)`. If that is the case, do it like this `self.in_grey = [160.] * (len(self.in_map) / 2)`. – Julia Mar 02 '19 at 17:40
  • `float` is a function that can create a float object from a number or suitable string. It can't be indexed. It also can't operate on a list. – hpaulj Mar 02 '19 at 20:13
  • @Julia i tried but i got another error TypeError: can't multiply sequence by non-int of type 'float'.. – abc Mar 03 '19 at 05:22
  • This has to do with the division operator `/`. `len(self.in_map) / 2` returns you a `float`. You cannot multiply a list and a float. This is what the error message tells you. Check this post https://stackoverflow.com/questions/21316968/division-in-python-2-7-and-3-3 about the difference of `/` in python 2 and python 3. – Julia Mar 03 '19 at 07:27
  • I tried float (160)....... and i resolve this issue, but got another error in self.blue1 = [0, 39, 102,1]*(len(self.score_lines)/2) TypeError: Can't multiply sequence by non-int of type 'float'.. – abc Mar 03 '19 at 07:40

0 Answers0