Jump to content

Null input to number crashes emulator


Geofellas

Recommended Posts

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 by Geofellas
Link to comment

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 by Geofellas
Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...