Jump to content
Sign in to follow this  
Followers 0
BoxmanCrew

concatinated zeros don't display

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

Share this post


Link to post

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

Share this post


Link to post

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.

Share this post


Link to post

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  
Followers 0

×