How do I add a item(words) in list

Get help using Construct 2

Post » Sun Jul 31, 2016 3:44 pm

is there an easy way to add 500 ++words in list from my wordpad??

or do i need to add everything one by one? oO
B
17
S
7
G
7
Posts: 205
Reputation: 5,335

Post » Sun Jul 31, 2016 5:42 pm

Have each word on its own line in a text file.
Add your text file as a "Project File". https://www.scirra.com/manual/141/files
Request the file using AJAX. https://www.scirra.com/manual/107/ajax
Parse out the words with the tokenat expression in a loop. Your source is "AJAX.LastData", your index is "loopindex", and your token is "newline" https://www.scirra.com/manual/126/system-expressions
Store in your data structure of choice, recommended array, or dictionary could work too. https://www.scirra.com/manual/108/array

Edit: Alternatively, for more advanced control over categories or nested data, you can use the XML Plugin. https://www.scirra.com/manual/139/xml
Mistakes were made.
B
53
S
27
G
114
Posts: 1,695
Reputation: 64,438

Post » Sun Jul 31, 2016 9:14 pm

Responding to PM from @cbelle requesting clarification here for the benefit of others.

AJAX is not just for images. By using the "Request project file" action, you can load the contents of your previously imported project file to memory. This is accessible through the AJAX.LastData expression.

With the conditions "AJAX on completed" and "repeat tokencount(AJAX.LastData,newline) times", you can loop through your text file and get each word with the expression "tokenat(AJAX.LastData,loopindex,newline)". Normally you would store each word in an array or dictionary, but if you want to put it directly in a list object you can do that as well by using the list's "Add item" action.

Edit: fixed tokencount expression
Last edited by oosyrag on Sun Jul 31, 2016 11:12 pm, edited 1 time in total.
Mistakes were made.
B
53
S
27
G
114
Posts: 1,695
Reputation: 64,438

Post » Sun Jul 31, 2016 11:00 pm

@oosyrag
and "repeat tokencount(AJAX.LastData) times" not work..:/ error on tokencount

if i just put a number
B
17
S
7
G
7
Posts: 205
Reputation: 5,335

Post » Sun Jul 31, 2016 11:11 pm

Sorry about that, it should be repeat tokencount(AJAX.LastData,newline).
Mistakes were made.
B
53
S
27
G
114
Posts: 1,695
Reputation: 64,438


Return to How do I....?

Who is online

Users browsing this forum: Lordshiva1948 and 6 guests