JanKy Posted August 27, 2018 Share Posted August 27, 2018 (edited) I know what a boolean is. True or false. But i don't understand how the variable "Radio Device", which changes, because it's a dayz server and that thing is an item and it is a *number*, was converted ( somehow ? ) to a boolean. Here is that specific part of the code. addCommandHandler("radiochat", function(player, _, ...) if (getElementData(player, "Radio Device") >= 1) then for _,v in ipairs(getElementsByType("player")) do if (getElementData(v, "Radio Device") >= 1) then if (getElementData(v, "radiochannel") == getElementData(player, "radiochannel")) then outputChatBox("#BCC643[Radio] "..getPlayerName(player):gsub("#%x%x%x%x%x%x", "").." : #d0e1e1"..table.concat({...}, " "):gsub("#%x%x%x%x%x%x", ""), v, 255, 255, 255, true); end end end else return end end); The thing is that i don't get the error on the first if which compares almost the same way the variable "Radio Device", but on the second if. And i don't know what is the problem. I bet it is something stupid and i don't see it.. ;/ Thanks in advance ^^ Edited August 27, 2018 by JanKy Link to comment
Moderators IIYAMA Posted August 27, 2018 Moderators Share Posted August 27, 2018 This will solve it in most cases: 1. If it is nil or false use OR to change it to the next value, which is in this case 0. getElementData(player, "Radio Device") or 0 2. If it was a string before, it is now converted to a number, with the lua function tonumber. "100" (string) is now converted to 100 (number) tonumber(getElementData(player, "Radio Device") or 0) 3. Apply your statement. if tonumber(getElementData(player, "Radio Device") or 0) >= 1 then addCommandHandler("radiochat", function(player, _, ...) if tonumber(getElementData(player, "Radio Device") or 0) >= 1 then for _,v in ipairs(getElementsByType("player")) do if tonumber(getElementData(v, "Radio Device") or 0) >= 1 then if getElementData(v, "radiochannel") == getElementData(player, "radiochannel") then outputChatBox("#BCC643[Radio] "..getPlayerName(player):gsub("#%x%x%x%x%x%x", "").." : #d0e1e1"..table.concat({...}, " "):gsub("#%x%x%x%x%x%x", ""), v, 255, 255, 255, true); end end end end end) 1 1 Link to comment
JanKy Posted August 27, 2018 Author Share Posted August 27, 2018 Thank you very much. It solved my problem ^^ 1 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