Best way to use random with lots of possible outcomes?

Just started using Construct 2? Post your questions here

Post » Wed Feb 11, 2015 11:35 am

Hi guys, I added a "random fact" area in one of my games just for some humorous stuff between levels to keep the player amused.

The way I did it was thus:

GlobalVariable: RandomFact = 0
SpriteFont: RandomFact = "" (blank)

On start of layout: Set RandomFact to choose(1,2,3,4,5,6,7,8,9)

RandomFact = 1, set SpriteFont: RandomFact = "That fly looks pretty mad. I better not get in his way."

RandomFact = 2, set SpriteFont: RandomFact = "Why is nobody else talking about the flying fish?"

etc. etc.

Every extra fact I want to add to the game I need an extra event to handle it. Pretty painful as on the free version I only have 100 events to work with.

Any clever stuff involving arrays I could be using instead?
B
4
Posts: 22
Reputation: 244

Post » Wed Feb 11, 2015 11:42 am

Depends a little on your random facts, you might as well just do a really simple thing, like: Set Text = choose("My first sentence","My second sentence","My third sentence","Well, this is getting LONG","But it does seem to take even more")

No variables, no unnecessary setting of anything, easy to edit. As long as you don't have a million facts it seems quite suitable.
B
19
S
6
G
6
Posts: 1,101
Reputation: 5,646

Post » Wed Feb 11, 2015 11:53 am

TomCarter wrote:Any clever stuff involving arrays I could be using instead?


Just the standard way.

FactArray (array):
x =0 : "fact 1"
x =1 : "fact 2"
x =2 : "fact 3"
x =3 : "fact 4"
etc

RandomFact (spriteFont):
RandomFact: set text to FactArray.at( random( FactArray.width))
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Feb 11, 2015 12:07 pm

Somebody wrote:Depends a little on your random facts, you might as well just do a really simple thing, like: Set Text = choose("My first sentence","My second sentence","My third sentence","Well, this is getting LONG","But it does seem to take even more")

No variables, no unnecessary setting of anything, easy to edit. As long as you don't have a million facts it seems quite suitable.


oh MAN!

Thanks this works perfectly and is literally the same thing but smoother. I totally over engineered this simple problem without thinking :P
B
4
Posts: 22
Reputation: 244

Post » Wed Feb 11, 2015 1:02 pm

Glad to help out - meanwhile codah's approach is probably a better bet if you had to use it in several places or had quite the amount of lines.
B
19
S
6
G
6
Posts: 1,101
Reputation: 5,646


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests