Jump to content

concatinated zeros don't display


BoxmanCrew

Recommended Posts

I've built a cartridge that collects user inputs, does a "numeric operation" to calculates a new value for the variable. I later concatenate those variables together to produce the geocache coordinates. When the new value has a leading zero it does not display in the concatenated value. Example N42 12.012 Will display as N42 12.12. What is the best way to make sure zero values are displayed?

 

A second issue I found was that if the user enters a 1 (for example) and I subtract 2 the resulting negative number will crash the cartridge when the concatenation is done. Is there a way to mistake proof this?

 

I am using Urwigo as my editor.

Edited by BoxmanCrew
Link to comment

OK. I found my own solution to the zero's being dropped. I did the concatenation into a new variable and set the type to string instead of number.

 

Still looking for suggestions on error proofing so I don't end up with a negative number if the user enters an incorrect value. Is there a way to set the resulting value to an absolute value? For now I changed the input to choice and limited the values available to prevent numbers that would not work properly.

Edited by BoxmanCrew
Link to comment

For the first problem, you could use the Lua function "tostring()" to convert a number into a string.

 

For the second, you could check the entered number in the input event. Check, if the number is lower than 0 or greater than 9. If so, display a message, that the number is wrong. If you don't want to give a hint, you could use the Lua function "math.abs()" (see http://lua-users.org/wiki/MathLibraryTutorial) to get the absolut value.

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...