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

Why is string.gmatch is returning nil's?

Asked by 8 years ago

I'm trying to test the string.gmatch iterator. Problem is, the captures I'm specifying are somehow transforming to nil!

local Colors = {}
print(script.Colors.Value)
for k, v in string.gmatch(script.Colors.Value, "([%a]+)") do    
    print(v)
end

The child of the script is the stringvalue Colors, which holds the string, "Hello World, Die People,Apple" Yet my output is

nil >nil >nil >nil >nil >nil

1 answer

Log in to vote
2
Answered by
funyun 958 Moderation Voter
8 years ago

string.gmatch does not work quite like pairs. It only returns matches, nothing else.

--Added the next two lines just to be safe.
script:WaitForChild("Colors")
repeat wait() until script.Colors.Value ~= ""

print(script.Colors.Value)
for match in string.gmatch(script.Colors.Value, "%a+") do --Not 'k', not 'v', just each match.
    print(match)
end

Ad

Answer this question