#How can I simplify this type construction?

1 messages · Page 1 of 1 (latest)

edgy hedge
#

Hello I'm quite new with the whole comptime concept, and I want to create a struct type that contains a array. This array will get it's size from the function argument but also it's default value. Currently I found how to do it using two arguments, one for the size and one for the default value, but I would prefer if it was just one.

    return struct {
        sprites: [sprite_qty]Sprite = sprites,
    };
}```

```shovel: game_object.GameObject(2, [_]Sprite{
    .{
        .texture = SpriteSheet.Sprites.shovel_base.z(),
    },
    .{
        .pos = .{ 0.0, 1.732, 0.0 },
        .texture = SpriteSheet.Sprites.shovel_top.z(),
    },
}) = .{},

Thank you

edgy hedge
#

It was simply to change my GameObject fn to be:

pub fn GameObject(comptime sprites: anytype) type {
    return struct {
        sprites: [sprites.len]Sprite = sprites,
    };
}
sleek fox
#
pub fn GameObject(comptime sprites: anytype) type {
    return struct {
        sprites: [sprites.len]Sprite = sprites,
    };
}