[SOLVED] Random Layout, does not work :(

Get help using Construct 2

Post » Fri Apr 19, 2013 2:55 pm

Hello and thanks for reading this message.

I was trying to make a video game that consists of several minigames. Each of these minigames is a layout.

I would like to start the game, the system will randomly one of those minigames, but can not get it to work.

I have read this post:
http://www.scirra.com/forum/can-the-system-randomly-select-the-next-layout_topic43927.html

I have made these actions and events:
[CODE]Global variable rd as number (= 0 default)
System->Start of layout - Action System-Global & local Variable - Set value
Variable: rd - Value: round(random(your_number_of_layouts)+1) (round() will give an integer) (+1 to prevent obtaining 0 as result of the random())
..SubEvent System-Compare Variable
..Variable: rd - = Equal to - Value:1
...Action: System - Go to Layout, pick your layout 1

..SubEvent System-Compare Variable
..Variable: rd - = Equal to - Value:2
...Action: System - Go to Layout, pick your layout 2

etc...[/CODE]
Here, the image:


But as I said, this does not work.

A greeting and thanks.jesusruiz2013-04-20 03:21:12
B
4
Posts: 17
Reputation: 261

Post » Fri Apr 19, 2013 3:00 pm

hello, all the compare event (rd=1, rd=2 , ...) have to be a sub event of the "On start of layout" event
B
12
S
3
G
4
Posts: 63
Reputation: 3,410

Post » Fri Apr 19, 2013 3:07 pm

Your event structure is way off. I strongly suggest that you read some beginner tutorials to become more familiar with the process of building events.

Basically, events have conditions and actions. If all of the conditions are met, then all of the actions will be performed. You're asking C2 to check if all of those conditions you've stipulated are true (start of layout, rd=1, rd=2, etc), and then, if they are true, excecute all of those actions you've specified.

You need to split up those events into a main event that sets the variable to a random number, and then individual sub-events that check that number to produce a result. Like this:
B
56
S
15
G
10
Posts: 910
Reputation: 11,972

Post » Fri Apr 19, 2013 3:18 pm

Thanks Mimiste

I have created sub-events, but now when I start the game, always get the layout 4.

The new image, am I doing something wrong?:


Thousands of thanks.

UPLOAD:
Thanks Geometrix, I see that my image is wrong. So try to do what you tell me, seeing the end result of your image.
jesusruiz2013-04-19 15:20:41
B
4
Posts: 17
Reputation: 261

Post » Fri Apr 19, 2013 3:20 pm

Just so you know, your random() statement generates a random number between 0 and 3. This can include numbers with decimals, so rd can equal 0.4, 1.5, etc.

I recommend using int() function to make sure it's always an integer.Excal2013-04-19 15:20:41
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,194

Post » Fri Apr 19, 2013 3:27 pm

I was going to mention that but I saw that he rounds it off, so I think he's aware of it.
B
56
S
15
G
10
Posts: 910
Reputation: 11,972

Post » Fri Apr 19, 2013 3:41 pm

Now, it works ^ _ ^

The final image to another user with the same problem:


Thanks to all who have answered me.
B
4
Posts: 17
Reputation: 261


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 17 guests