I'm working on making a plugin that shows info on a script when it is selected, and know how to test for the selection and get the name, but how do I count how many lines it has?
COMMUNITY QUESTION
How do I count the line count of a script?
1 answer
You would have to get the source of the script(as Spongocardo stated) and reconstruct the entire text-I had already done something like this. This is heavily based off of BuildIn Libraries' Helper Library.
function getSource(s)
local lines = {};
local str = "";
for i = 1, string.len(s.Source) do
if (string.sub(s.Source, i, i) == "\n") then
lines[#lines+1] = str;
str = "";
else
str = str..string.sub(s.Source, i, i);
end
end
if (str ~= "") then
lines[#lines+1] = str;
end
return lines;
end
Now you could do #lines to find how many lines it has.
2 comments
0
I think I got it using mostly the %c string pattern thing, but haven't tested it yet as I still need to make it be displayed with a GUI and add some cool random features in.
0
Well, that didn't work, trying this way now.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
You can use the Source property to get the source of a script. I wouldn't know how to make it so it count the lines, but it would definitely involve string patterns. http://wiki.roblox.com/index.php?title=String_patterns