Best way to use random with lots of possible outcomes?

0 favourites
  • 5 posts
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • 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?

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

  • Try Construct 3

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

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

  • 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

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

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