+BoxmanCrew Posted July 2, 2017 Share Posted July 2, 2017 (edited) 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 July 2, 2017 by BoxmanCrew Quote Link to comment
+BoxmanCrew Posted July 2, 2017 Author Share Posted July 2, 2017 (edited) 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 July 2, 2017 by BoxmanCrew Quote Link to comment
+charlenni Posted July 3, 2017 Share Posted July 3, 2017 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. 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.