I’m trying to use the raylib drawText() function. The first argument is a string and I want to print a value with the string. While I can’t concatenate it like "Mode: " ++ @tagName(gameMode) I found a solution, where I can use it with another raylib function: rl.textFormat(). This function takes a string and an anytype, and returns a string.
Here’s some of my code:
So you can tell, I would like to print the text on the screen based on which state of the game I’m in.
This is the compiler error I get: error: cannot pass '[:0]const u8' to variadic function return std.mem.span(@call(.auto, cdef.TextFormat, .{@as([*c]const u8, @ptrCast(text))} ++ args));
I know the %c might be bad too, but couldn’t find any other solution.
This is an example code that works, this is where I’m copying the idea:
rl.textFormat uses C-style variadic arguments, so you need to pass all arguments separately. For this reason, you don’t need to surround them with .{}.
rl.drawText(rl.textFormat("Mode: %d", .{@as(i32, @intFromEnum(gameMode))}), 10, 30, 20, rl.Color.red);
This works, but obviously I would like to see the string and not the value.
I think its fault of a raylib-zig. It can certanly cast passed [:0]const u8 to [*c]const u8 on its own as it does with text argument. Also @ptrCast is unnecessary there)