FSXTim Posted May 27, 2012 Share Posted May 27, 2012 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
Castillo Posted May 27, 2012 Share Posted May 27, 2012 Labels don't support HEX codes, you can't do it. Although, around the forums there was a function to make it color coded. Link to comment
FSXTim Posted May 27, 2012 Author Share Posted May 27, 2012 (edited) Do you know this function? If yes, could you please tell me about it? Greets Edited May 27, 2012 by Guest Link to comment
Castillo Posted May 27, 2012 Share Posted May 27, 2012 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
FSXTim Posted May 27, 2012 Author Share Posted May 27, 2012 Okay, forget it, my label will have the colour 'white'. This is not my level! But thanks, sir! Link to comment
Alpha Posted May 27, 2012 Share Posted May 27, 2012 You don't need to understand it, you can simply use that code. Link to comment
FSXTim Posted May 27, 2012 Author Share Posted May 27, 2012 But I have to change function guiCreateColorLabel( ax, ay, bx, by,str, bool, parent ) to function guiCreateColorLabel( 0.6639,0.383,0.1826,0.0638,"",true,zeit_Window) right? Greets Link to comment
Alpha Posted May 27, 2012 Share Posted May 27, 2012 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
FSXTim Posted May 27, 2012 Author Share Posted May 27, 2012 Okay, thanks! But I don't understand it completely. How would the script look like, if the text in the label is the following? Time in [color=#FF0000]London[/color] 'Time in' is white and 'London' is red. Greets Link to comment
Alpha Posted May 27, 2012 Share Posted May 27, 2012 Do you know hex color codes? guiCreateColorLabel( 0.6639,0.383,0.1826,0.0638,"#FFFFFFTime in #FF0000London",true,zeit_Window) Link to comment
FSXTim Posted May 27, 2012 Author Share Posted May 27, 2012 No, I didn't know them! No, just fun, but I didn't know if it is able to use hex color codes in this function. Thanks! Greets Link to comment
Alpha Posted May 27, 2012 Share Posted May 27, 2012 That's the point of the custom function. Link to comment
FSXTim Posted May 27, 2012 Author Share Posted May 27, 2012 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
Wei Posted May 27, 2012 Share Posted May 27, 2012 guiCreateColorLabel(0.1494,0.383,0.4689,0.0638,"#FFFFFFTime in #FF0000London",true,uhrzeit3 ) Try Link to comment
Alpha Posted May 27, 2012 Share Posted May 27, 2012 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
FSXTim Posted May 27, 2012 Author Share Posted May 27, 2012 @blazy This cannot work, because the label has to be on my window and 'uhrzeit3' is not my window. @Alpha No errors, but no the label sais that: 'Time in' 'London' is missing! Greets Link to comment
Alpha Posted May 27, 2012 Share Posted May 27, 2012 I think it's the function itself, might not be working correctly. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now