How do I random layout?

Get help using Construct 2

Post » Fri Jun 26, 2015 10:11 am

I have several layouts and want to add an action to go to random layout. Can someone help me out? I can not find anything about it.
B
4
Posts: 33
Reputation: 266

Post » Fri Jun 26, 2015 10:21 am

on action > go to layout by name choose("layout1","layout2", "layout3")

this will choose one of the three layouts by random

You can also put the layouts names in variables and use "layout" &variable to make the string shorter.
Last edited by Anonnymitet on Fri Jun 26, 2015 10:56 am, edited 1 time in total.
B
55
S
24
G
13
Posts: 765
Reputation: 12,571

Post » Fri Jun 26, 2015 10:49 am

I tried the first option and syntax error :?
B
4
Posts: 33
Reputation: 266

Post » Fri Jun 26, 2015 10:54 am

Did you write the string exactly like this below?

choose("layoutname1", "layoutname2", "layoutname3")

You have to use " before and after each layouts name and a comma between each layout.

"Layoutname" should of course be changed to a real layout name in your project :)
B
55
S
24
G
13
Posts: 765
Reputation: 12,571

Post » Fri Jun 26, 2015 10:59 am

Ok, sorry my fault. :)
And so as not to repeat the layout once started? that is, random but never repeat
B
4
Posts: 33
Reputation: 266

Post » Fri Jun 26, 2015 11:02 am

I think that arrays would be best for that so when a layout has been used it gets removed from the array. But that is quite complicated if you're not experienced with arrays. But very very useful to learn to use early which I didn't :P

Take a look here:

https://www.youtube.com/watch?v=ZPG1t-gZfds
B
55
S
24
G
13
Posts: 765
Reputation: 12,571

Post » Fri Jun 26, 2015 11:31 am

Thanks, really if it seems complicated.
Perhaps someone has a different and simpler method.
B
4
Posts: 33
Reputation: 266

Post » Fri Jun 26, 2015 1:31 pm

SYSTEM > SELECT LAYOUT BY NAME > choose("name1","name2","name2,"name3")

in this example, the system will select a random layout searching by the name... in this case we have 4 layouts ("name1","name2","name2,"name3") ... the "name2" layout appears 2 times, it means that there is one more chance to the system select the layout name2...

To make it not repeat, you can try to use variables, for example: if the current layout is the name1 , so, the variable layout1 will be = 1 and then you can compare variables and make the things work.

I hope it is not too confuse.
B
5
S
1
Posts: 60
Reputation: 495

Post » Fri Jun 26, 2015 2:30 pm

Marto wrote:Thanks, really if it seems complicated.
Perhaps someone has a different and simpler method.


Arrays aren't complicated, but like many data structures, can be a bit hard to conceptualize at first. They're extremely useful, worth learning, and in this case, the best solution.

Example
B
63
S
19
G
8
Posts: 341
Reputation: 12,130

Post » Thu Aug 20, 2015 12:21 pm

@caiocesar

Can you please explain more how to make layouts not repeating by making Variables? It will be SO helpful.
- Sashik
B
25
S
8
G
1
Posts: 13
Reputation: 3,032

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 14 guests