How do I use a random number to choose an image?

0 favourites
  • 5 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • Hi there. New to Construct, I switched from Phaser because I have no idea what I'm doing as far as coding goes. What I'd like to do is have a variable called "plot1" which chooses a number from 1 to 10 and then picks the image to show based on the number generated.

    Here's the coding I tried to execute:

    But I'm assuming I did it wrong and it's not working.

  • It should be random(1,10) a comma not a - Let me know how it goes.

    Edit: Also, as I observe I notice that random doesn't do 1,2,3 it is odd numbers like 1.123232, 2.2325252. So I personally like to round my randoms. Such as Round(Random(1,10)).

    Edit 2: Also, as far as the image goes, you could also change the image itself (Have different images in different animation frames). So instead of Set position, you could set frame based on the number If you need help just let me know.

  • Tried it this way and not working. :C

  • Oh haha 1 second, sorry. I'll get a screen of what I mean. You should have an "Add Action" setting p1 to something. I'll respond in a second.

    Edit: This is what I mean:

    On start of layout (or any time you want) make it so that it sets the variable p1 to round(random(1,10)).

    And then you have it check to see what p1 is and set the position. The way you had it wasn't working because it wasn't setting the variable, it was checking it.

    Sorry, I should have realized that sooner.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you for your help!

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