Noki Posted April 20, 2014 Share Posted April 20, 2014 ERROR: test\c_world.lua:3: attempt to compare number with string function setClientTime(cmd, newTime) if not newTime then outputChatBox("Enter a number between 0 and 23") return end if (newTime > 23) or (newTime < 0) then outputChatBox("You must enter a number between 0 and 23.") return end setTime(tonumber(newTime), 0) end addCommandHandler("settime", setClientTime) There's my code. I don't know why it's showing an error. I've experimented, but nothing will work. Client side. I want to create a settime command, where you can adjsut the time in the argument after. I cannot seem to even do that with this code. I know to remove line 3, 4, 5 and 6 for it to work, but I want to tell the player that he must put a valid number in. I don't want it just fixed, but if someone could tell me what I was doing wrong, I'd appreciate it. Thanks. Link to comment
Tete omar Posted April 20, 2014 Share Posted April 20, 2014 Hi, The structure of the handler function of addCommandHandler is: string commandName, [string arg1, string arg2, ...] Which means the extra arguments (string arg1, string arg2, ...) are always strings, what you should do here is to convert the argument to number, and this works by using tonumber; Here you go: function setClientTime(cmd, newTime) newTime = tonumber ( newTime ) if not newTime then outputChatBox("Enter a number between 0 and 23") return end if (newTime > 23) or (newTime < 0) then outputChatBox("You must enter a number between 0 and 23.") return end setTime(tonumber(newTime), 0) -- What is this? end addCommandHandler("settime", setClientTime) 1 Link to comment
Noki Posted April 20, 2014 Author Share Posted April 20, 2014 Thank you very much. Works perfectly. I didn't even think of doing that. Link to comment
Tete omar Posted April 20, 2014 Share Posted April 20, 2014 You're welcome, reading the wiki is most likely a way of debugging your scripts. 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