How do I assign a random variable's value to a text

0 favourites
  • 3 posts
From the Asset Store
OpenAI TTS
$10 USD
Text-to-Speech plugin.Allows your Construct 3 project to convert written text into spoken words
  • Let's say I have some text variables named for example text1, text2, text3.

    I pick a random number out of these three. Number 2 would mean that text2 was chosen. Now, how do I assign the text of text2 (using randomly chosen number) to another variable?

    I'm facing tons of such variables, so a simple switch won't do.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Although I'm pretty sure you aren't using the smartest way to get to where you want to be the easiest way to do this in the way you've set things up would be:

    set text : choose(text1,text2,text3)

    You might want to take a look at the dictionary object, the array object, things like the expression tokenat() and other text expressions, though if you are going to have that much changeing text in your project, though..

  • Although I'm pretty sure you aren't using the smartest way to get to where you want to be the easiest way to do this in the way you've set things up would be:

    set text : choose(text1,text2,text3)

    You might want to take a look at the dictionary object, the array object, things like the expression tokenat() and other text expressions, though if you are going to have that much changeing text in your project, though..

    But the problem in my situation is the number of all the variables.

    The simpliest way to do it would be something like this:

    if(randomized_number==1) final_text=text1;

    if(randomized_number==2) final_text=text2;

    ...and so on.

    I'm trying to do sth more like that:

    if(randomized_number==number) final_text=textnumber;

    I'm struggling to figure out how, though.

    EDIT:

    ....but actually your way works fine. Thanks

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