How do I split strings to fetch arguments?

Get help using Construct 2

Post » Sun Mar 05, 2017 3:14 pm

Hi guys, I've got a text file with a few lines like so:

Code: Select all
ViLa4480»5-6*
ViLa4480»5-6*
ViLa4480»1-2*
Manimani»5-64*


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: Select all
ViLa4480 1,2
Manimani 5,64


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!
B
10
S
3
Posts: 51
Reputation: 1,226

Post » Sun Mar 05, 2017 4:01 pm

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

Image
B
10
S
3
Posts: 51
Reputation: 1,226

Post » Sun Mar 05, 2017 11:46 pm

@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
B
94
S
33
G
20
Posts: 438
Reputation: 17,605

Post » Mon Mar 06, 2017 12:10 am

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
B
94
S
33
G
20
Posts: 438
Reputation: 17,605

Post » Fri Mar 17, 2017 6:15 pm

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.
B
10
S
3
Posts: 51
Reputation: 1,226


Return to How do I....?

Who is online

Users browsing this forum: Apollo14, MaujDeveloper, totoe and 5 guests