Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I count the line count of a script?

Asked by 10 years ago

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?

0
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 Spongocardo 1991 — 10y

1 answer

Log in to vote
1
Answered by
ked2000 15
10 years ago

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.

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. dudemanloserr 15 — 10y
0
Well, that didn't work, trying this way now. dudemanloserr 15 — 10y
Ad

Answer this question