Need help with tokenat()

0 favourites
  • 6 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • I have 2 layouts, one layout has multiple buttons so when you click each one, it stored the loopindex of the clicked button in a global variable.

    Now on the 2 layout, I have multiple text files with datas separated by "|". Each text filename is in this format "file_1", "file_2", "file_3", etc.

    So what I am trying to accomplish is when the 2 layout loads, then tokenat should load corresponding file datas.

    tokenat("file_"&"clickedID"&".Text", loopindex, "|")

    The above does not work. Any ideas?

    Thanks

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It looks like you're using an expression like tokenat("file_1.Text", 0, "|"). This looks wrong because it only makes sense to use tokenat if the string actually has the separater character in it. "file_1.Text" has no "|" characters in it, so it won't do anything useful.

    I would guess you intended to load the contents of the file, not pass the name of the file.

  • It looks like you're using an expression like tokenat("file_1.Text", 0, "|"). This looks wrong because it only makes sense to use tokenat if the string actually has the separater character in it. "file_1.Text" has no "|" characters in it, so it won't do anything useful.

    I would guess you intended to load the contents of the file, not pass the name of the file.

    Hi Ashley, I do have a text object with name "file_1" which has all the datas separated by "|" so I am looking at an easier way to call that file in tokenat since I have multiple text object with incremental name.

    If I do this tokenat(file_1.Text, 0, "|") then its fine but I have file_2 ... file_40, so I need a way to load each file data based on the button clicked from previous layout.

  • I'm not clear what you're doing now, your original example used a string of the filename but your reply suggests you're not doing that now. If you are successfully loading the first file, then I guess just do that for a different file for the next layout?

    tokenat isn't really suitable for large amounts of data, I'd advise using a more structured data format like JSON.

  • First you need to request the file "file_"&"clickedID"&".Text" with AJAX.

    When AJAX request is completed, then you need to use tokenat() to parse the data from the file. So your code should look like this:

  • First you need to request the file "file_"&"clickedID"&".Text" with AJAX.

    When AJAX request is completed, then you need to use tokenat() to parse the data from the file. So your code should look like this:

    That is it, thanks for that and bravo

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