Daw588
(Daw588)
October 15, 2020, 6:50pm
#1
I am not sure why my syntax highlighter does not highlight the first int
keyword.
local editor = script.Parent
local function format(s, c)
return "<font color=\"".. c.. "\">".. s.. "</font>"
end
editor.FocusLost:Connect(function()
local syntax = editor.Text
for _, v in pairs({"int"}) do
syntax = syntax:gsub("(%W)(".. v.. ")(%W)", function(l, str, r)
return l..format(str, "#859900")..r
end)
end
editor.Text = syntax
end)
I am using RichText feature
4 Likes
Ashp116
(Ashp116)
October 15, 2020, 6:51pm
#2
could you elaborate on your problem?
1 Like
Daw588
(Daw588)
October 15, 2020, 6:52pm
#3
Well, it does not highlight all int
words. As you can see, it only highlights the second int
word.
sjr04
(uep)
October 15, 2020, 6:53pm
#4
this only goes through a single element
perhaps use for v in string.gmatch(editor.Text, "int")
?
Daw588
(Daw588)
October 15, 2020, 6:54pm
#5
Wait, how I suppose to use it?
Ashp116
(Ashp116)
October 15, 2020, 6:54pm
#6
is this in ROBLOX, or some other editor?
Daw588
(Daw588)
October 15, 2020, 6:55pm
#7
My roblox game that highlights code
Ashp116
(Ashp116)
October 15, 2020, 6:59pm
#8
try this
local editor = script.Parent
local function format(s, c)
return "<font color=\"".. c.. "\">".. s.. "</font>"
end
editor.FocusLost:Connect(function()
local syntax = editor.Text
for _, v in string.gmatch(string.lower(editor.Text),string.lower("int")) do
syntax = syntax:gsub("(%W)(".. v.. ")(%W)", function(l, str, r)
return l..format(str, "#859900")..r
end)
end
editor.Text = syntax
end)
1 Like
KJry_s
(MalleoZephyris)
October 15, 2020, 7:00pm
#9
Did you turn the property instead the text on ?
Ashp116
(Ashp116)
October 15, 2020, 7:01pm
#10
I am still trying to figure out smth. How many times does the for loop run? Only Once, or Multiple times
Daw588
(Daw588)
October 15, 2020, 7:01pm
#11
Yeah I did turn the property on.
KJry_s
(MalleoZephyris)
October 15, 2020, 7:05pm
#12
Oh, I found what the issue was; source: RichText [TextScaled Support Added]
Checked one of their examples;
<font color= "rgb(240, 40, 10)">red text</font>
You forgot to use
"rgb("..c..")"
Oh and just to be sure change c to a string with:
"rgb("..tostring(c)..")"
so the “format” function would be:
local function format(s, c)
return "<font color=\"".. "rgb("..tostring(c)..")".. "\">".. s.. "</font>"
end
Wait a second, you gotta be quotes around a few parts. (Nvm you already did this.)
Daw588
(Daw588)
October 15, 2020, 7:07pm
#13
I don’t think so. I used this person’s post to make this.
By far, the BEST UI update in a really long time!
Syntax highlighting has never been easier Code is a botch, I know, but at least it works
<a class="lightbox" href="//devforum-uploads.s3.dualstack.us-east-2.amazonaws.com/uploads/original/4X/e/a/a/eaab152fa64d7cf87d1d53c8bc0188aa4f8cf4b6.png" data-download-href="/uploads/short-url/xtYgOvA2qt3MchVrHmATtCR9jqm.png?dl=1" title="2020-09-06-10-14-19-620, 100%" rel="noopener nofollow …
KJry_s
(MalleoZephyris)
October 15, 2020, 7:12pm
#14
Can you show me what you send as the color and text paremeters?
Oh and it might be because you forgot to add Quotes to the s;
return "<font color=\"".. c.. "\">\"".. s.. "\"</font>"
Btw, can you send me what’s the Text is after you used this function once.
Daw588
(Daw588)
October 15, 2020, 7:15pm
#15
nothing, happens.
however if I use it multiple times it will work on all other ones…
Your issue is your gsub pattern.
Replace (%W)(keyword)(%W)
with (%W?)(keyword)(%W?)
1 Like
Daw588
(Daw588)
October 15, 2020, 7:20pm
#17
it works. one more question, how can I make it format it after changing the text, because when I tried to, then it would just get into infinite loop.
You should have a seperate TextLabel for the formatted code, instead of editing the TextBox’s text. They can overlay eachother to look as if they’re a single one, they just have seperate text.
KJry_s
(MalleoZephyris)
October 15, 2020, 7:21pm
#19
Yeah okay so I can see a lot wrong with it; if you don’t put any text in it:
<font color= "#859900"></font>
it won’t do anything and literally use that as the text:
when I used it with text: i literally put this inside the text property:
<font color= "#859900">text </font>
then it became:
Daw588
(Daw588)
October 15, 2020, 7:23pm
#20
I will try to do that. Give me a minute.