Jump to content

'guiSetText()' with two Colours


FSXTim

Recommended Posts

Hello,

I created a label, as you can see here:

uhrzeit3 = guiCreateLabel(0.1494,0.383,0.4689,0.0638,"",true,zeit_Window) 
guiSetFont(uhrzeit3,"default-bold-small") 

Colour: white

How can I do that 'London' is red? This doesn't work:

guiSetText(uhrzeit3, "Uhrzeit in #FF0000London:") 

Greets

Link to comment
function guiCreateColorLabel( ax, ay, bx, by,str, bool, parent ) 
    local pat = "(.-)#(%x%x%x%x%x%x)" 
    local s, e, cap, col = str:find( pat, 1 ) 
    local last = 1 
    local r,g,b 
    while s do 
        if cap == "" and col then r,g,b = tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ) end 
        if s ~= 1 or cap ~= "" then 
            local w = dxGetTextWidth( cap ) 
            avc321 = guiCreateLabel( ax, ay, ax + w, by,cap,bool,parent ) 
            if not r then r = 255 end 
            if not g then g = 255 end 
            if not b then b = 255 end 
            guiLabelSetColor( avc321,r,g,b ) 
            ax = ax + w 
            r,g,b = tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ) 
        end 
        last = e + 1 
        s, e, cap, col = str:find( pat, last ) 
    end 
    if last <= #str then 
        local cap = str:sub( last ) 
        local w = dxGetTextWidth( cap ) 
        local avc123 = guiCreateLabel( ax, ay, ax + w, by,cap,bool,parent ) 
        guiLabelSetColor( avc123,r or 255,g or 255,b or 255 ) 
        return avc123 
    end 
end 

If that doesn't work, then search for "guiCreateColorLabel".

P.S: I didn't make that function.

Link to comment

But don't change the function name itself.

Example:

--You use the function like this: 
guiCreateColorLabel( 0.6639,0.383,0.1826,0.0638,"",true,zeit_Window) 
  
--but define the function as it is: 
function guiCreateColorLabel( ax, ay, bx, by,str, bool, parent ) 
    local pat = "(.-)#(%x%x%x%x%x%x)" 
    local s, e, cap, col = str:find( pat, 1 ) 
    local last = 1 
    local r,g,b 
    while s do 
        if cap == "" and col then r,g,b = tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ) end 
        if s ~= 1 or cap ~= "" then 
            local w = dxGetTextWidth( cap ) 
            avc321 = guiCreateLabel( ax, ay, ax + w, by,cap,bool,parent ) 
            if not r then r = 255 end 
            if not g then g = 255 end 
            if not b then b = 255 end 
            guiLabelSetColor( avc321,r,g,b ) 
            ax = ax + w 
            r,g,b = tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ) 
        end 
        last = e + 1 
        s, e, cap, col = str:find( pat, last ) 
    end 
    if last <= #str then 
        local cap = str:sub( last ) 
        local w = dxGetTextWidth( cap ) 
        local avc123 = guiCreateLabel( ax, ay, ax + w, by,cap,bool,parent ) 
        guiLabelSetColor( avc123,r or 255,g or 255,b or 255 ) 
        return avc123 
    end 
end 

Link to comment

Yea, you're right! ;)

Still having a problem:

Error (line1): attempt to call glocal 'guiCreateColorLabel' (a nil value)

guiCreateColorLabel(0.1494,0.383,0.4689,0.0638,"#FFFFFFTime in #FF0000London",true,zeit_Window) 
  
function guiCreateColorLabel( ax, ay, bx, by,str, bool, parent ) 
    local pat = "(.-)#(%x%x%x%x%x%x)" 
    local s, e, cap, col = str:find( pat, 1 ) 
    local last = 1 
    local r,g,b 
    while s do 
        if cap == "" and col then r,g,b = tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ) end 
        if s ~= 1 or cap ~= "" then 
            local w = dxGetTextWidth( cap ) 
            avc321 = guiCreateLabel( ax, ay, ax + w, by,cap,bool,parent ) 
            if not r then r = 255 end 
            if not g then g = 255 end 
            if not b then b = 255 end 
            guiLabelSetColor( avc321,r,g,b ) 
            ax = ax + w 
            r,g,b = tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ) 
        end 
        last = e + 1 
        s, e, cap, col = str:find( pat, last ) 
    end 
    if last <= #str then 
        local cap = str:sub( last ) 
        local w = dxGetTextWidth( cap ) 
        local avc123 = guiCreateLabel( ax, ay, ax + w, by,cap,bool,parent ) 
        guiLabelSetColor( avc123,r or 255,g or 255,b or 255 ) 
        return avc123 
    end 
end 

Greets

Link to comment

The problem is, you're calling the function as soon as the script starts, and the script starts from up all the way down.

So it first meats your call to the function guiCreateColorLabel, while you haven't even defined it yet.

So you have to put the call for the function below the function declaring.

function guiCreateColorLabel( ax, ay, bx, by,str, bool, parent ) 
    local pat = "(.-)#(%x%x%x%x%x%x)" 
    local s, e, cap, col = str:find( pat, 1 ) 
    local last = 1 
    local r,g,b 
    while s do 
        if cap == "" and col then r,g,b = tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ) end 
        if s ~= 1 or cap ~= "" then 
            local w = dxGetTextWidth( cap ) 
            avc321 = guiCreateLabel( ax, ay, ax + w, by,cap,bool,parent ) 
            if not r then r = 255 end 
            if not g then g = 255 end 
            if not b then b = 255 end 
            guiLabelSetColor( avc321,r,g,b ) 
            ax = ax + w 
            r,g,b = tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ) 
        end 
        last = e + 1 
        s, e, cap, col = str:find( pat, last ) 
    end 
    if last <= #str then 
        local cap = str:sub( last ) 
        local w = dxGetTextWidth( cap ) 
        local avc123 = guiCreateLabel( ax, ay, ax + w, by,cap,bool,parent ) 
        guiLabelSetColor( avc123,r or 255,g or 255,b or 255 ) 
        return avc123 
    end 
end 
  
guiCreateColorLabel(0.1494,0.383,0.4689,0.0638,"#FFFFFFTime in #FF0000London",true,zeit_Window) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...