How do I send a sentence to an array as separate values?

Get help using Construct 2

Post » Mon Oct 13, 2014 4:51 am

Hi there,

Is it possible to send a sentence of words to an array and add each word of this sentence to a separate value on the x-axis?

Example sentence: 'What is that?'
In this case I would like to send the word 'what' to X0, the word 'is' to X1 and the word 'that' to X2.

Thanks for your help!

Ruud.
Image
B
54
S
24
G
12
Posts: 96
Reputation: 10,316

Post » Mon Oct 13, 2014 5:03 am

Condition: Repeat tokencount("What is that?"," ")
Action: Set array.at(loopindex, 0) to tokenat("What is that?",loopindex, " ")
B
28
S
8
G
4
Posts: 553
Reputation: 4,914

Post » Mon Oct 13, 2014 9:53 pm

Hi DuckfaceNinja,

thanks for your fast reply!
I can't get it to work the way I would like to though...

Would you mind if I posted my project so you can take a look at it?

Thanks again!

Ruud.
Image
B
54
S
24
G
12
Posts: 96
Reputation: 10,316

Post » Tue Oct 14, 2014 4:10 am

Rjan wrote:Hi DuckfaceNinja,

thanks for your fast reply!
I can't get it to work the way I would like to though...

Would you mind if I posted my project so you can take a look at it?

Thanks again!

Ruud.

I don't have C2 in front of me now, but it is always better to post one anyway, others can take a look at it. The best capx will be a minimal and specific to your issue, don't post one with valuable assets though, or a complete game. (if the game has been coded significantly)
B
28
S
8
G
4
Posts: 553
Reputation: 4,914

Post » Tue Oct 14, 2014 4:37 am

It's no fancy project. Not yet, anyway... ;)
It's my first one, so don't be to harsh on me, haha.

On start of the game, the first player gets three random words. He has to use these words to make some sentences. (still have to find a way to check if the three words are actually used...).
Then player two has to make a part of the story, using three random words from the text that player one wrote.
Then it's player's one turn again, and so forth.
When done, you click 'Done! Create story' and all the text's are 'glued' together...

Thanx again!
You do not have the required permissions to view the files attached to this post.
Image
B
54
S
24
G
12
Posts: 96
Reputation: 10,316

Post » Tue Oct 14, 2014 3:50 pm

Event 6 is wrong, you're setting the value at the index "Array.At(loopindex, 0)" when you should simply be setting the value at "loopindex". The kind of error I tend to make and NOT see it until I restart my events completely... :lol:
B
67
S
27
G
24
Posts: 969
Reputation: 18,573

Post » Tue Oct 14, 2014 5:30 pm

I'm afraid that doesn't work either...
In the first value of my array I still get all three words instead of having the words being split up into tree different values in the array...
Image
B
54
S
24
G
12
Posts: 96
Reputation: 10,316

Post » Tue Oct 14, 2014 5:47 pm

Fixed :) I think :)

Tell a Story (1).capx


Event should look like this as Magistross said

Untitled.png


Not like you had it here

Untitled2.png
You do not have the required permissions to view the files attached to this post.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763


Return to How do I....?

Who is online

Users browsing this forum: JaredX, ksiads, Magistross, Rable and 6 guests