The statement
if(input.keyDown[W]) GAME_DATA.position.offset(vec2(0, -deltaTime));
fails with
error: incompatible types: '&Vec2T(f32)' and 'void'
if(input.keyDown[W]) GAME_DATA.position.offset(vec2(0, -deltaTime));
^
note: type '&Vec2T(f32)' here
if(input.keyDown[W]) GAME_DATA.position.offset(vec2(0, -deltaTime));
^
note: type 'void' here
if(input.keyDown[W]) GAME_DATA.position.offset(vec2(0, -deltaTime));
^
Where
pub fn offset(self: &Self, other: &const Self) -> &Self {
self.data[0] += other.data[0];
self.data[1] += other.data[1];
return self;
}
Fixed by
// Ignoring the return value
if(input.keyDown[W]) _ = GAME_DATA.position.offset(vec2(0, -deltaTime));
or
// Wrapping in braces , which reveals the return value ignored error.
if(input.keyPressed[W) { GAME_DATA.position.offset(vec2(0, -deltaTime)); }
or
// Redefining offset to not return the reference to self
pub fn offset(self: &Self, other: &const Self) {
self.data[0] += other.data[0];
self.data[1] += other.data[1];
}
The behaviour is correct, I just think the error is unergonomic.
The statement
fails with
Where
Fixed by
or
or
The behaviour is correct, I just think the error is unergonomic.