How do I Correctly use tokenat

0 favourites
  • 3 posts
From the Asset Store
Choose the winner correctly and earn as much score as you can!
  • Hi

    I am currently storing and loading using ajax various text files for my project. The format of the text file in this example is as follows

    Text 123 - Text 456;

    Text 789 - Text 10112;

    |

    So each line has a - and a ; as a delimiter , the - allows for the two texts value to be split out and the ; is for the end of that line. The | is a record separator . So I load this format into the array using the | to store each record into each cell of the array.

    My problem is trying to get the text before and after the - . On the first line this works :

    Textobject1.Text = trim(tokenat(array.at(counterpos),0,"-"))

    Textobject2.Text = trim(tokenat(array.at(counterpos),1,"-"))

    But when I try and use this logic for the second line :

    Textobject2.Text = trim(tokenat(array.at(counterpos),2,"-"))

    Textobject3.Text = trim(tokenat(array.at(counterpos),3,"-"))

    Textobject2 does not equal the value before the - but the value afterwards and textobject3 shows the value from the next line (which is not here in this example).

    My reason for holding the data in this way is I am storing each type of language verb per record and then the various definitions of that verb e.g. I am , they are etc on each line.

    Any help to solve this would be appreciated

    ** EDIT **

    Still struggling to get this to work so if I am using tokenat incorrectly or if there is another/better way of doing this I would appreciate if someone could advise on that. Not sure if this is any clue to the problem but the file is loaded via an included event sheet and that sheet then calls the function from the original sheet that called it and that the file is saved in a UTF-8 format to preserve the accents for the language.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • When using - as your token, the expression does not take into account the ;. So for the source, the tokens age broken up as follows:

    (Text 123 )-( Text 456;

    Text 789 )-( Text 10112;)

    Which would be tokens 0,1, and 2.

    If you must use that format, you will want to use nested tokenats, first with ";", then with "-".

  • thanks oosyrag for your answer on this it explains why I was struggling with this and will explain why my below method works as well.

    However , I have found a work around for this by storing the string from the array into a single text variable while removing the ; at the same time and then stripping out the text before and after the - from that variable when storing it into the text objects.

    A little long winded but it works but I will consider to try nested tokenats

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