Two text colors on one line?

I’m making a hud and i want the players balance and salary on the same line but in two different colors, is there a way about doing this?

Use two separate DrawText calls, but put one after the other.

Wouldn’t that require me to choose two different positions for the text? I want them to be right next to eachother no matter the value much like they would if they were in the same drawtext call

You can use

surface.GetTextSize to get the width of the first section so you can place the second right after.

Find out the width of the first line (http://wiki.garrysmod.com/page/surface/GetTextSize), then find out the width of “blank” space in given font. So X location of second call would be: x = x+1stlinewidth+widthofspacebar (or simply include the spacebar in the second call.)

#edit
code, half assed, idk if its gonna work.



local text1 "I am red "
local text2 = " and I am green"
surface.SetFont("font")
surface.SetTextColor(255,0,0,255)
surface.SetTextPos(20,40)
surface.DrawText(text1)

local x,y = surface.GetTextSize( text1 )
surface.SetTextColor(0,255,0,255)
surface.SetTextPos(20+x,40)
surface.DrawText(text2)



Thanks, there were a couple problems but i fixed em