[Help] Randomizing string array

Get help using Construct 2

Post » Sat Jul 27, 2013 8:48 pm

Currently i am working on a game which require the player to solve the question by phrasing words, every time i start my layout it will randomize a sentence.

Example:
I have randomize a sentence of 9 words with 9 text label:
My name is Jerry and i hate Cat Tom

i manage to shuffle the words by putting them into array, randomize them and then comparing them by each text labels.

But now i have a problem here for this sentence:
My name is Jerry and her name is Jane

You notice there are 2 "is" and 2 "name" How i can shuffle such sentence by comparing text labels? Been trying this for 2 days and i am still stuck.

P.S, I've used the search button but no solutions found. And yeah, i am newbie. CraiggieSaurus2013-07-27 20:50:07
B
5
S
1
Posts: 11
Reputation: 553

Post » Sat Jul 27, 2013 11:13 pm

Perhaps you could just as a letter to it in the array (so 'is' and 'isa'), then alter the displayed text. So like: set text to array.at(0), text = 'isa', set text to 'is'.

There's probably a cleaner way, but this is pretty simple as is.
B
28
S
8
G
5
Posts: 429
Reputation: 7,007

Post » Mon Jul 29, 2013 2:22 am

maybe i never explain myself clearly, all the sentence are dynamic which can be edited by .txt file and i wont know how many words is going to be in the sentence or what words is that.
B
5
S
1
Posts: 11
Reputation: 553

Post » Mon Jul 29, 2013 6:22 am

You could assign each world a number. So first whole sentence is put into an array in order like "My name is Jerry and her name is Jane" so "My"=1 "name"=2 "is"=3... and then when you shuffle you will have each word correctly numbered but at random position.
ImageImageImageImage
B
157
S
66
G
41
Posts: 2,597
Reputation: 34,821

Post » Mon Jul 29, 2013 6:34 am

Do you want the words just random, or 'random' but they can't be in their original position? Having duplicates makes this a harder problem.
ImageImageImage
B
71
S
21
G
230
Posts: 3,687
Reputation: 128,845


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, MikaelS, nahima, PreacH and 18 guests