[Help] Randomizing string array

0 favourites
  • 5 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)