• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

Legacy GM Drawing Characters One By One With Different Colors

Rikifive

Member
Hello there,

Currently I'm trying to draw a text, where characters would be printed one by one and where some words would be drawn in a different color, to highlight them.

However, I'm not sure how to approach that. I tried to think of something, but that all quickly became confusing.

What exactly I'm trying to do
-----------------------------------------

Because I'm planning to release the game in multiple languages, I store all the text in external .txt files, so the strings are loaded from there.

Now basically what I'm trying to achieve is this:


I was thinking of a format like this perhaps?
Code:
text = "/c0Press /c4[Z] /c0key to jump."
- where { /c0 } would set the draw color to colour with ID 0 specified somewhere earlier; { /c4 } would be colour with ID4 - orange, for example.

Another thing worth keeping in mind is line breaking. Being able to specify text box dimensions when calling a script would be perfect, but manual line breaking with a similar tag would be okay.

How should I approach this?

Hmm... I'll try something with 'for' method and string scanning and see what can be done.

If you have ideas, I'd appreciate help; Thanks.

--------
EDIT READ BEFORE REPLYING TO AVOID WASTING YOUR TIME :p
Somebody pointed out, that something I had in mind is doable; so after getting few tips, I gave it a legit try and after some time I managed to achieve what I wanted.

At the moment it's pretty much basic (manual), but I'll improve (automate) it later.

INPUT
Code:
"That's a string with \C1RED\C0, \C2GREEN \C0and\B\C3BLUE \C0words."
OUTPUT



Consider that as solved; thanks to ones, who gave tips. c:
 
Last edited:

NightFrost

Member
For textbox line breaking, you can use string_width (and the _ext version). You just need the textbox width at hand and split the text at spaces. Track the length of already written line in variable, then compare written width + next word width to textbox width and decide if you can write on same line or have to move to next. This doesn't guarantee vertical fit; if you need it, you'll have to pre-process the entire text to get the total number of lines and adjust textbox height accordingly.
 

Rikifive

Member
May I ask what code you are using? I want to do the same thing.
Basically the drawing is handled by a loop ( for i ) with draw_texts for each character. That itself is for drawing them one by one, based on timer.
Now the trick is, that each character is scanned for commands (by if statement in the loop), so if there will be " \ ", it will trigger command search based on next character to it; then instead of drawing that part (putting on screen), it will trigger code related to drawing manipulation, such as changing color and then proceed with drawing next characters.
While it all works, I'm still working on the code- improving it, that is. And it was kinda designed for my needs, not sure if it would be user-friendly for 3rd party users. I think I saw scripts for that somewhere, but I wanted to make that myself- I prefer knowing what the code is about and how it works, rather than use something I don't understand, which will make it harder when wanting to customize it.

For textbox line breaking, you can use string_width (and the _ext version). You just need the textbox width at hand and split the text at spaces. Track the length of already written line in variable, then compare written width + next word width to textbox width and decide if you can write on same line or have to move to next. This doesn't guarantee vertical fit; if you need it, you'll have to pre-process the entire text to get the total number of lines and adjust textbox height accordingly.
Thanks for information, but I already implemented auto-line break. :p I just wasn't sure about the general idea of handling that text (as stated in OP), as there are multiple ways to achieve that- but now that I had the basics, further improvements aren't problematic.

Hah, though to be honest I didn't notice that _ext version of string_width ~ I went with that normal one.
But that way I had full control I suppose, configuring it the way I want. - It all works, so can't complain.
And to make it optimized - it calculates things just once. So before starting drawing, it alters the string itself by adding commands for line breaks where needed. So basically, if the next word won't fit, the code will add " \B " before it, which will do the thing while drawing.
The performance isn't bad too- it turned out, that silly menu animations apparently make CPU work harder (harder, do not confuse with hard - there are low values), than drawing pretty long texts with this method. :p

Here's how it works at the moment:
INPUT:
Code:
test_string=This is a\C1 relatively long string\C0, that will\C1 not fit \C0into a single line. It will be \C2automatically divided \C0into multiple lines based on \C3calculations \C0made in order to get the drawn word's width.\B\BThe process details are visible on the \C1poorly designed\C0, budget \C3black box to the left\C0.\B\BThere also are \C4multiple colors \C0in case you didn't notice. How fancy!\B\BNow a single word longer than the drawing area:\C1 1234567890123456789012345678901234567890123456789012345678901234567890
OUTPUT:


I may add animations in future... Didn't really need those yet, but it should be easy to configure these when the need arises.
 
Top