How do you make an textbox change colors like the Script Editor?
Example:
How do you make an textbox change colors like the Script Editor?
Example:
I’m not too sure as I’ve never used it but RichText
and the code
font will help you here
I ain’t that good in lua, could you give me an example?
for word, color in pairs(words) do
local format = string.format("<font color=\"rgb(%d, %d, %d)\">%s</font>", color.R, color.G, color.B, word)
-- automatically formats the string for the textbox. Example Result: <font color="rgb(255, 0, 0)">keyword</font>
-- do stuff
end
You could use the RBX Lexer for detecting keywords and tokens as syntax highlighting isn’t exactly easy.
I didn’t understand that Can you show me an example on how to make comments grey maybe?
I’m not good with syntax highlighting so i’d only be able to give you this:
local font_color = "<font color=\"rgb(%d, %d, %d)\">%s</font>" -- default for the syntax highlighting
local comment_string = "%-%-.+" -- comment string format
local function getComment(_string: string, pattern: string) : string | nil
return _string:match(pattern) -- this returns whether not not it was able to find a string match with the string pattern
end
local function formatComment(_string: string) : string
local s = getComment(_string, comment_string)
if s then -- check if the string was a match
return font_color:format(65, 65, 65, s) -- this formats the string into xml and returns it
end
return "" -- this returns a default blank value
end
print(formatComment("-- this is a comment")) -- this prints the formatted xml comment
For you to do your own syntax highlighting, you’d have to learn string patterns and rich text