Stuff by David
All my stuff in one place!
Home/News
Videos
Applications
Games
Resources
About me
Minecraft Note Block Studio tutorials
The Poptart Tragedy
Building songs in Minecraft
Redstone Display Maker tutorial
Auto closing wooden door!
View all...
Minecraft Note Block Studio
Redstone Display Maker
Minecraft Redstone Simulator
The ultimate D&D to GML converter
Image to RTF converter
View all...
Chaos
Die
View all...
Game Maker examples
Labyrinth generator and solver
Tetris
Text editor
Inventory and item engine
View all...
Game Maker scripts
GML syntax coloring in-game
Change colors of certain words in a text
Center the text in the built-in dialogues
Upgrade of keyboard_string
View all...
<
Previous
|
All scripts
|
Next
>
Change colors of certain words in a text
Please enable javascript to view this.
/* CALL: draw_text_colortags(x, y, str) INFO: Draws a text exactly like draw_text, but with this script, you can use simple color tags to change the colors of certain words. EXAMPLE: draw_text_colortags(x, y, "[c=255]Red text[/c], [c=$00FF00]green text[/c] and [c=c_blue]blue text[/c]!") ARGUMENTS: x = The x position to draw the text. y = The y position to draw the text. str = The string to draw. RETURNS: Nothing. WRITTEN BY: Davve http://www.stuffbydavid.com No credit needed, but appreciated. */ { var xx, yy, str, st, et, ct, l, h, stl, pc, dx, dy, dp, p, c, ds, i; xx = argument0; yy = argument1; str = argument2; st = '[c='; et = ']'; ct = '[/c]'; l = string_length(str); h = string_height(' '); stl = string_length(st); pc = draw_get_color(); dx = xx; dy = yy; dp = 1; for (p = 1; p <= l; p += 1) { c = string_char_at(str, p); if (c == chr(10) || p == l || (c == '#' && string_char_at(str, p - 1) != '\')) { draw_text(dx, dy, string_copy(str, dp, p - dp + 1)); dp = p + 1; dx = xx; dy += h; } else if (c == string_char_at(st, 1) || c == string_char_at(ct, 1)) { if (p + string_length(st) <= l && string_copy(str, p, string_length(st)) == st) { ds = string_copy(str, dp, p - dp); draw_text(dx, dy, ds); dx += string_width(ds); i = string_copy(str, p + stl, string_pos(et, string_delete(str, 1, p + stl))); p += string_length(i + et + st) - 1; if (i == '') i = pc; draw_set_color(execute_string('return ' + string(i))); dp = p + 1; } else if (p + string_length(st) <= l && string_copy(str, p, string_length(ct)) == ct) { ds = string_copy(str, dp, p - dp); draw_text(dx, dy, ds); draw_set_color(pc); p += string_length(ct) - 1; dp = p + 1; dx += string_width(ds); } } } draw_set_color(pc); }
Comments
Constructive criticism is always welcome!
Please enable JavaScript to view comments.