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

Get help using Construct 2

Post » Sat Jun 06, 2015 8:24 am

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.
B
3
Posts: 2
Reputation: 179

Post » Sat Jun 06, 2015 8:53 am

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..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Jun 06, 2015 9:44 am

LittleStain wrote: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 ;)
B
3
Posts: 2
Reputation: 179


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, FabianB, gskunk and 50 guests