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

Just started using Construct 2? Post your questions here

Post » Tue Jun 10, 2014 10:19 pm

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:
Image

But I'm assuming I did it wrong and it's not working.
B
4
Posts: 3
Reputation: 208

Post » Tue Jun 10, 2014 10:33 pm

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.
B
28
S
5
G
5
Posts: 98
Reputation: 4,794

Post » Tue Jun 10, 2014 10:49 pm

Image
Tried it this way and not working. :C
B
4
Posts: 3
Reputation: 208

Post » Tue Jun 10, 2014 11:14 pm

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:

Image

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.
B
28
S
5
G
5
Posts: 98
Reputation: 4,794

Post » Tue Jun 10, 2014 11:28 pm

Thank you for your help!
B
4
Posts: 3
Reputation: 208


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests