string.lower screwing up spaces?

Hi, I’m trying to compare a string with what’s given to me with onplayerchat and i dont care if they use capitals or not, though, if I use string.lower, it won’t let me use spaces in the string, or it’ll never respond.

example

(ans is already defined, assume ans = Riot Games)

if I type riot games, it doesnt work, if I type Riot Games, it does. I assume string.lower doesnt work with spaces? Can I have some help with this?

[lua]hook.Add( “OnPlayerChat”, “chatbot”, function( ply, message, team, dead )

if ans == ((message) or string.lower(message)) then
– stuff
end

end)[/lua]

http://puu.sh/4Zxsm.png

Because message is valid.

For example:



local a = b or 1 -- a = 1, be does not exist
local b = (a + 1) or 0 -- b = 2 because a +1 is valid.

------ soooo.....

local bool = (2 == (a or b)) -- bool = false because a exists and does not equal 2


ok? :smiley:

I’m still slightly confused. How would I use it correctly then?



hook.Add( "OnPlayerChat", "chatbot", function( ply, message, team, dead )

if (ans == message) or (ans == string.lower(message)) then
-- stuff
end

end)


[editline]26th October 2013[/editline]

Also, wouldn’t you want to use string.lower on ans instead?

ans is already defined, and I dont want it to change. The players answer though, needs to be accepted though by either lower case or whatever they want.

http://puu.sh/4Zy8L.png

Still doesnt seem to work. I don’t understand it still.

I know it is, but if ans is Riot Games, then no matter what the message is, or what capitalisation is used, it will have to be Riot Games.

string.lower(ans) = “riot games”
so if message == string.lower(ans), and if message is ‘riot games’, then it would be true.

Oh! Now I get it. Fixed! Thanks!

Best way to make it foolproof:

[lua]if string.lower(ans) == string.lower(message) then[/lua]