How do I merge texts

Get help using Construct 2

Post » Sat Oct 04, 2014 11:09 am

Hi there,

I'm a bit lost developing my app.
What I need is the following: there are two players, each of which in turn add text into a textblock.
At a certain moment I would like to merge all these texts together in one textfield.

The question is: how can I store each player's entry and put them all together in the end?
I've been trying to accomplish this with arrays, webstorage and dictionary but I just don't know how to store things and 'glue' them together...
Please advice if one of the mentioned plugins can do the work and if so, how?
On the other hand, there might be a better solution?

Many thanks in advance,
Ruud.
Image
B
54
S
24
G
12
Posts: 96
Reputation: 10,326

Post » Sat Oct 04, 2014 11:29 am

text1&text2&"Something else"&variable1&array.at(0,1) etc
& being the glue
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Sat Oct 04, 2014 1:59 pm

Thanks Dutoit!
Should have known that...works the same as in Java...

However I still have some questions.
If I want to store the player's entries, which is best to use: arrays, webstorage or dictionary and how to add the entries? With some kind of while loop?
Or, as I mentioned, maybe there is a much better solution...?

Thanks again.
Image
B
54
S
24
G
12
Posts: 96
Reputation: 10,326

Post » Sat Oct 04, 2014 3:06 pm

Would use arrays, it offers more flexibility... but dictionary will also work. Of course whatever you choose, save to webstorage, very easy to do...
Check tutorial section you can save array to json or dictionary to json and save that json to webstorage, then all you do is load from webstorage "yourspecialdata" into your array or dict on start of app...

No need for while loop can save directly via text or whatever...

What you making, might be easier knowing what you trying to do, to offer best solution.

For instance I use functions and param, very effective, each param is a set of data...
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Sat Oct 04, 2014 5:25 pm

I'm trying to create a simple word-game.
Player 1 gets three random words and has to make some sentences, using all three words.
Then it's player's 2 turn: player 2 can't see the text that player 1 has written. He also gets 3 random words from the sentences player 1 has made.
Then it's player's 1 turn again, and so forth...
Ultimately there's one button that 'glues' the complete story together.

Nothing fancy, but I only started with C2 a couple of weeks ago so still learning and still reading... ;)

I managed to put all the players entries into a global variable, but when player 1 has entered his sentences, I can't get C2 to pick three random words out of the global variable...

Hope this makes any sense?
Image
B
54
S
24
G
12
Posts: 96
Reputation: 10,326

Post » Sat Oct 04, 2014 8:21 pm

I don't really like to write code for people, I rather people try it out for themselves and learn, especially new users...but there are so many examples doing things one way, I thought I would try another way and use more advanced techniques. I know you are new, and this is a little over your head, but if you can grasp this, then you are on your way.
You didn't exactly choose the easiest app to start with - lol.

This was done quickly. It as raw, and needs some TLC etc etc etc. It is an example, done quickly - okay - lol

This to steer you in a direction - to get you to focus your learning on certain things. Check the manual and tutorials to find out more about what I tried to do, what I used.
It works, it just isn't completed in any way or form... Its just to nudge you in the right direction.

Okay... I...
Created 2 functions, save and retrieve.
Functions pass on params and return values

I and you will use tokenat( it is the easier, but regex is also an option) I counted the spaces (" ") to determine number of words, I created a temp array to store 3 random numbers based on number words. So you don't randomly select same word, of course if player1 has written a word 2 or more times, player2 might get it twice or more.

I used tokenat to find the 3 random words using the temp random numbers.

Anyways, all the time I have.

You can find tutorials on all that I have used, obviously in separate tutorials, I just combined them.
You do not have the required permissions to view the files attached to this post.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Mon Oct 06, 2014 9:40 am

Damn Dutoit, you ROCK!
You rock big time! :-)

You're right, what you made is not excactly my level (yet), but I would like to thank you anyway!
I'll dive into it and see how far I will come :-)

Thanks again for your time!
Image
B
54
S
24
G
12
Posts: 96
Reputation: 10,326


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 10 guests