Search code examples
pythonursina

Error: TypeError: Voxel.__init__() got an unexpected keyword argument 'position'


I am trying to make minecraft in ursina but whenever I run it, it says:

TypeError: Voxel.__init__() got an unexpected keyword argument 'position'

This is my code

from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController

app = Ursina()
player = FirstPersonController()
Sky()
block = load_model('block.obj')
grass_texture = load_texture('grass_block.png')

class Voxel(Button):
      def __init__(self, positon = (0,0,0)):
            super().__init__(
              parent = scene,
              position = position,
              model = block,
              origin_y = 0.5,
              texture = grass_texture,
              color = color.color(0,0,random.uniform(0.9, 1)),
              highlight_color = color.lime)
      def input(self, key):
          if self.hovered:
            if key == 'left mouse down':
              voxel = Voxel(position = self.position + mouse.normal)
              
            if key == 'right mouse down':
                  destroy(self)
                  


for z in range(20):
      for x in range(20):
            voxel = Voxel(position = (x,0,z))


app.run()

Solution

  • There's a typo in Voxel's initializer declaration:

    def __init__(self, positon = (0,0,0)):
    

    You have positon (instead of position).
    Correct that, and you should be fine:

    def __init__(self, position=(0, 0, 0)):