Hello,
I'm currently translating some C code to Zig by hand, and I wanted to make one of the structure more “Zig-like” by adding an init function.
However, I'm having an “expected field initializer” error that I don't understand how to fix (on lines .qline[] and .vx[] .vy[]).
const qix_line_count: i32 = 20;
const QixLine = struct { x: [2]i32, y: [2]i32, color: u16 };
const Qix = struct { qline: [qix_line_count]QixLine, vx: [2]i32, vy: [2]i32, head: i32, tail: i32, initialized: i32, color_angle: i32,
pub fn init() Qix {
return Qix {
.head = 0,
.tail = qix_line_count - 1,
.qline[0].x[0] = random_num(k_screen_width),
.qline[0].y[0] = random_num(k_screen_height),
.qline[0].x[1] = random_num(k_screen_width),
.qline[0].y[1] = random_num(k_screen_width),
.qline[0].color = 0,
.color_angle = 0,
.vx[0] = random_num(17) - 8,
.vy[0] = random_num(17) - 8,
.vx[1] = random_num(17) - 8,
.vy[1] = random_num(17) - 8,
.initialized = 1,
};
}
};
Thank you for your time and answers!