What's wrong with `postion`, I did it correctly?

Viewed 42
from ursina import *
#preloads a cube
class Voxel(Button):
    def __init__(self):
        super().__init__(self, position = (0,0,0))(
        parent = scene,
        position = position,
        model = 'cube',
        origin_y = 0.5,
        texture = 'white_cube',
        color = color.white,
        highlight_color = color.lime)

app = Ursina()
#loads a cube
for z in range(8):
    for x in range(8):
        Voxel = Voxel(position = (x,0,z))


app.run()  

the error is here please help me:

File "D:\project\game.py", line 18, in <module>
    Voxel = Voxel(position=(x,0,z)) TypeError: Voxel.__init__() got an unexpected keyword argument 'position' 

so what I'm trying to do with this code is make cubes

1 Answers

You likely copy-pasted to the wrong place.

For example, this part of your super call (self, position = (0,0,0)), was probably intended for your class __init__ method.

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

Moving that makes your class functional.

class Voxel(Button):
    def __init__(self, position = (0,0,0)):
        super().__init__(
        parent = scene,
        position = position,
        model = 'cube',
        origin_y = 0.5,
        texture = 'white_cube',
        color = color.white,
        highlight_color = color.lime)

You also need to change the name of your class instance at Voxel = Voxel(position = (x,0,z)) from Voxel to something else. As it stands, anything after the first loop would refer to an instance of Voxel and not the class itself.

Full working code:

from ursina import *
#preloads a cube
class Voxel(Button):
    def __init__(self, position):
        super().__init__(
        parent = scene,
        position = position,
        model = 'cube',
        origin_y = 0.5,
        texture = 'white_cube',
        color = color.white,
        highlight_color = color.lime)

app = Ursina()
#loads a cube
for z in range(8):
    for x in range(8):
        voxel = Voxel(position = (x,0,z))


app.run() 
Related