• string.find issues..
    2 replies, posted
[lua]function test(Nick) for k, v in pairs(player.GetAll()) do print(string.lower(v:Nick())) print(string.lower(Nick)) if(string.find(string.lower(v:Nick()), string.lower(Nick)) == 1) then return v end end return false end[/lua] That function runs...the print output is: (btw my ign is [TRUE]Kevin) [true]kevin (this one is a print(Args[1]) in the main function.) [true]kevin [true]kevin but returns false I am assuming the string.find is having trouble with the brackets considering everyone in the game without them can be attacked with the command. I don't know anything about string.find or really any string commands so if there is something I can do to make this work that would be nice. According to what I read on the wiki about string.find this should be returning true on the if statement, resulting in v being the player in question..
string.find uses patterns, Lua's version of regex. You need to set the 3rd and 4th argument for it to use plain text. string.find(haystack, needle, 1, true) Where 1 is the start index and true means don't use patterns. You also don't have to test for == 1, you can simply use ~= nil or just nothing at all. It also looks like you could just use string.sub(pl:Name():lower(), 1, #Name) == Name:lower() If what you're trying to do is match partial names.
Ah, seems to be working now, I tried that same thing, but thought that the boolean had to be set to false to not use patterns, and true to use them. Thanks
Sorry, you need to Log In to post a reply to this thread.