#trying to create syntax highlighting

6 messages · Page 1 of 1 (latest)

bronze ivy
#
local codebox = script.Parent
local runservice = game:GetService("RunService")
local redWords = {
    "if", "local", "return", "while", "function", "end",
    "and", "do", "for", "type", "typeof", "or", "until", "not",
    "else", "elseif", "break", "continue", "then"
}

codebox.RichText = true
codebox.TextEditable = true 

local lastText = ""

runservice.RenderStepped:Connect(function()
    local inputText = codebox.Text
    if inputText ~= lastText then
        for _, word in pairs(redWords) do
            inputText = inputText:gsub("(%f[%a])("..word..")(%f[%A])", 
                '<font color="rgb(255, 75, 75)">%2</font>')
        end
        codebox.Text = inputText
        codebox.CursorPosition = #codebox.Text + 1
        lastText = codebox.Text
    end
end)

why does the text turn red only when the user clicks out of the text box?

#

like if we had this:

local a = 2
local b = 3
print(a+b)

the local would turn red when we arent typing

#

but when we type it becomes like this:

<font color="rgb(255, 75, 75)">local</font> a = 2
<font color="rgb(255, 75, 75)">local</font> b = 3
print(a+b)
spark citrus
bronze ivy
spark citrus