So I asked a similar question before, and so far I've had no problems. Here's the code.
pub fn add_combat_log(self : *InfoLog, attacker : *ent.Entity, victim : *ent.Entity, damage : usize) void {
const count = comptime std.fmt.count("{s} took {} damage from {s}!",
.{"A very large name", 255, "A very large name"});
var buf : [count + 1]u8 = undefined;
const text = std.fmt.bufPrintZ(&buf, "{s} took {} damage from {s}",
.{victim.name, damage, attacker.name}) catch unreachable;
std.debug.print("{s}", .{text});
self.add_log(text);
}
And here is how I draw the log
pub fn render(per_data : *pData.PersistentData) void {
for(0..hud_cfg.LOG_MAX) |l| {
const text = per_data.log.log[l];
const y : f32 = @floatFromInt(hud_cfg.LOG_AREA_Y + hud_cfg.LOG_AREA_HEIGHT - hud_cfg.BORDER_SIZE -
(l * hud_cfg.LOG_TEXT_SEPARATOR + 10));
const x : f32 = hud_cfg.LOG_AREA_X + 10;
if(text.len > 0) {
rl.DrawTextPro(
per_data.get_font().*,
text.ptr,
rl.Vector2 {
.x = x,
.y = y,
},
rl.Vector2 {
.x = 0,
.y = 0,
},
0,
hud_cfg.LOG_TEXT_SIZE,
2,
rl.YELLOW
);
}
}
}
For some reason, the drawn text is completely wrong and weird characters. But the debug printed text to the console is correct. I don't understand.