I am new to Zig (and system languages in general outside of C in college). So excuse me if this is a B question for an A problem lol but I don't know any better.
I am looking to store a slice of struct pointers in a struct field, to make some shared behavoir a little easier for a little physics simulator.
const obj = motion.Motion1DOF.new_basic("MotionBoi", 1.0, 0.0, [_]*forces.Force{ &simple, &spring });
}
Here I try to intialize my struct using a method new_basic, wich has the following definition:
pub const Motion1DOF = struct {
name: []const u8,
max_pos: f64,
min_pos: f64,
pos: f64 = 0.0,
vel: f64 = 0.0,
accel: f64 = 0.0,
net_force: f64 = 0.0,
mass: f64 = 1.0,
connections: []*forces.Force,
pub fn new_basic(
name: []const u8,
max_pos: f64,
min_pos: f64,
connections: []*forces.Force,
) Motion1DOF {
const new_motion = Motion1DOF{ .name = name, .max_pos = max_pos, .min_pos = min_pos, .connections = connections };
// Init connections to ensure two way
// Errors with this are handled a the connection level in init_connection
for (connections) |connection| {
connection.*.init_connection(new_motion);
}
return new_motion;
}
Unfortunatly, I am unable to get success, and the compiler is telling me somthing that I am sure is very smart but I don't have the brain power to decode.