Castillo Posted August 12, 2010 Share Posted August 12, 2010 hey, i added a PM system into my player menu but the problem is that players can send empty messages so im trying to cancel that but dunno why dosnt works, here is my code. addEvent ("sendMsg", true) addEventHandler ("sendMsg", getRootElement(), function(msg,client) local givenplayer = getPlayerFromName ( client ) if( givenplayer ) then if msg == nil then outputChatBox ( "* PM from " .. getPlayerName(source) .. ": " ..msg.. ".", givenplayer, 243, 151, 12 ) else outputChatBox ("Error: You cant send empty messages.", source, 255, 0, 0, false) end end end) Thanks in advance. Link to comment
50p Posted August 12, 2010 Share Posted August 12, 2010 If msg is always string then it will never be nil. You can check if string is empty by checking its length (with #) or "". if msg == "" then -- message is empty... end -- OR if #msg == 0 then -- message is empty... end Link to comment
dzek (varez) Posted August 12, 2010 Share Posted August 12, 2010 post whole code maybe? or try if msg==nil or msg=='' or msg==false then Link to comment
Castillo Posted August 12, 2010 Author Share Posted August 12, 2010 yea that worked, thanks. Link to comment
LonelyRoad Posted August 12, 2010 Share Posted August 12, 2010 Solid, it's irrelevant here to your question, but read your code more carefully, specifically line 6 and think about how it would work. Regards. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now