Search code examples
stringfunctiontext

How to show variables in text in raylib


I have a question regarding the raylib.c game library.

I'm trying to show the amount of hit points a player has left using the DrawText function.

I got it working after looking at an example game, but I don't really know what they did in the function to show the score.

DrawText(FormatText("Score: %i", Score), 10, 10, 20, LIGHTGRAY);

That was the code.

The first of the part with formattext is a string that has to be written using the const char* variable type. But I'd like to know how this actually works with the variable since it just a normal integer (Score). I tried a lot of things to get it working (even converting a variable into a string and then into a const char*. But that didn't work.

So I'd like to know what the %1 means, because if I delete it stops drawing the score.

@MonsterBrain gave a good explanation about my question:

%i means substitute that portion of text with value of the integer variable passed next. I think it's similar to printf function in C.


Solution

  • %i means substitute that portion of text with the value of the integer variable passed next.

    I think it's similar to the printf function in C.