How do I split strings to fetch arguments?

0 favourites
  • 5 posts
From the Asset Store
Fetch Quest
$19.99 USD
Fetch Quest 1 music pack is a collection of 10 in-game music loops.
  • Hi guys, I've got a text file with a few lines like so:

    ViLa4480»5-6*
    ViLa4480»5-6*
    ViLa4480»1-2*
    Manimani»5-64*[/code:1t185mtn]
    
    The idea is that I've got a few usernames and two arguments for each. My intention is to put them in some sort of database (be it an array, object or, preferably, TaffyDB). But I only want one registry per username. For the example lines above, I would like to see only 2 registrations with 2 arguments each:
    [code:1t185mtn]ViLa4480 1,2
    Manimani 5,64[/code:1t185mtn]
    
    I've built some code that is able to do this for simple usernames (no arguments), based on the "*" as an identifier between names, but i'm still not able to split the arguments into their own cell in the database and prevent them from repeating themselves.
    
    What would you guys think is the best approach to deal with this situation?
    
    Thank you in advance,
    ViLa4480 - the newbie programmer!
  • So this is my current plan to tackle this problem:

    1. Separate sentences by * [DONE]

    2. Ignore exact clones [DONE]

    3. Importing sentences to a temporary array [DONE]

    4. Extract the username from each array cell

    5. Import usernames to DB

    6. Extracting arguments from each array cell and overwriting the DB for each username

  • vila4480

    you are very close to how I would do it...

    just use tokenat again to split the username from the other argument...

    see my example:

    http://www.rieperts.com/games/forum/split_userdata.capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Just read how you wanted two arguments per username...

    The first version I made would only keep the arguments from the first time the username appears.

    I wasn't sure if there was some other method you would want to use to decide which arguments to save if the username appears multiple times in the original text file, so I made a new version that compares the arguments if the username is found and keeps the lowest values... (This gives the results you asked for in the first post).

    http://www.rieperts.com/games/forum/split_userdata2.capx

  • Awesome replies thank you guys!

    I think my method is working rather well but theres still some bug fixing to do regarding some other details!

    Ill get back to this later on.

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