String's manipulation?

This forum is currently in read-only mode.
  • Hello people,

    I know that it's a noob question, but I began to use Construct yesterday, and I don't know much about it.

    I'm doing a software to my dad that generates a radar code to his GPS. I thinked it would be simple to do, but I'm having many difficulties.

    Well, first, I have an Edit Box. In this editbox, user must enter latitude (e.g.: S3.34022). So, I would like that when user clicks on the button, a Text would be defined to -3.34022 (remove the "S", add a "-" and so write the number). I tried many things, but nothing works.

    If I use float(EDITBOX.Text), doesn't work too. Because when I write "S" on Editbox, the program ignores all numbers after it.

    Am I doing something wrong?

    Thanks.

  • When converting a string to a number, the string must begin with the number. It stops as soon as there is anything else. For example int("2g34") will return 2, float("3.2H45") will return 3.2, and float("S3.34022") will return 0, as it starts with a letter.

    But there is an easier way to achieve the results. As I understand, latitudes may be written as with "N" and "S" or "+" and "-" in the beginning. If so, then just use replace()

    + Button: On Button clicked

    -> System: Set global variable 'latitude' to replace(Uppercase(EditBox.Text), "N", "+")

    -> System: Set global variable 'latitude' to replace(global('latitude'), "S", "-")

    -> Text: Set text to global('latitude')

    latitude is a text variable

    This event will first convert the text of the editbox to uppercase, then replace all "N" in that text with "+" and all "S" with "-". This way, the user can enter the latitude in any way, e.g. "+3.34", "N3.34", "n3.34"

    However, you still have to make sure the latitude is not entered incorrectly.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks to both =)

    Well, I tried to read a tutorial written by Ashley, but it didn't help me... and I searched in Google, but didn't find nothing too.

    Tulamide, it didn't work. But thanks anyway! I'll try again later =).

  • Tulamide, it didn't work. But thanks anyway! I'll try again later =).If it doesn't work, then you've done something wrong. For me it works like a charme, as you can see here:

    <img src="http://dl.dropbox.com/u/11182740/pictures/latitude.png" border="0">

    I will share the cap with you, but you should try to find your mistake, in order to learn. And maybe try something else for a start, to get used to CC?

    LatitudeConversion.cap

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)