+Geofellas Posted August 25, 2008 Share Posted August 25, 2008 (edited) I am trying to get a user to input a value into a numeric variable and compare it against the value of another variable. This works fine provided a number is actually input but if the user enters nothing at all (in the emulator), it barfs. Both CheckValue and CorrectCode are numeric. function zinputSecretCode:OnGetInput(input) CheckValue = tonumber(input) if CheckValue == CorrectCode then Wherigo.Dialog{{Text=[[OK - that looks good - ]] .. CheckValue ..[[. Carry on and good luck finding the cache :)]],},} end end So I thought, lets make these string variables instead. But then the compare doesn't return a "true" even when correct (as I have been able to determine is the case with some debug messages). I am also worried about using a numeric variable anyway - what if the user enters a non numeric character? Edited August 25, 2008 by Geofellas Quote Link to comment
+Geofellas Posted August 25, 2008 Author Share Posted August 25, 2008 (edited) I am trying to get a user to input a value into a numeric variable and compare it against the value of another variable. This works fine provided a number is actually input but if the user enters nothing at all (in the emulator), it barfs. Both CheckValue and CorrectCode are numeric. function zinputSecretCode:OnGetInput(input) CheckValue = tonumber(input) if CheckValue == CorrectCode then Wherigo.Dialog{{Text=[[OK - that looks good - ]] .. CheckValue ..[[. Carry on and good luck finding the cache :)]],},} end end So I thought, lets make these string variables instead. But then the compare doesn't return a "true" even when correct (as I have been able to determine is the case with some debug messages). I am also worried about using a numeric variable anyway - what if the user enters a non numeric character? OK - always the way - post a question then figure out the answer. I needed to test for CheckValue == nil before displaying the dialog (setting it to 0 in that case) Still not sure why the string compare doesn't work Also if you enter a non numeric, tonumber(input) seems to return either null or 0 Edited August 25, 2008 by Geofellas Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.