changing layout Randomly

Get help using Construct 2

Post » Sun May 31, 2015 11:02 pm

hello
I created several layout and I want that when a layout is complete go to Another layout randomly. In addition to this I disable layout once it has been completed so as not to repeat . Is this possible?

Sorry if something is not understood, because I do not speak English properly .

thank you very much
B
5
Posts: 34
Reputation: 295

Post » Mon Jun 01, 2015 12:13 am

Ok here is a Youtube video to how I generate random instances if you don't understand the line of codes below. https://www.youtube.com/watch?v=PFD-giJ208E
Create a GROUP called "Call ran Function 1" Duplicate this group and have the second one disabled on start. The reason is to ultimately prevent the error of have 0 layers visible to the player by following the rest of this guide! It will hopefully all work for you if you follow every line step by step. Private message me or hope somebody has a more condensed way of doing this. It's all problem solving, but hopefully I solved all of the potential problems in this post.

Here is the Random Event lines of code to put into the both Call Random Function Groups. Make sure to set the second one inactive on start.
on Function "ran" / Set Return Value floor(random(Function.Param(0),Function.Param(1)+1))

* I don't know how often you want every layout to change, but here's an example of the next line of code

Every X Seconds (5 seconds)/ Call Function "ran" Paramater (1,4) *This number is the number of layouts you have. If you have 20 layouts then set the first parameter to 1 and the seconds parameter to 20. When you press done in Construct 2 it will look like Call Function "ran" (1,20)

*Now your return values are changing between 1 through 20 once every 5 seconds randomly.

Create Events like this for all 20 Layouts
*Do not use Function Return Value condition I had problems with it and System/Compare Two Variables does the same thing in theory and worked for me so use that.
System- Compare Two Values - Function.ReturnValue - Equals - 1 - Layout 1 is visible - / System - Go to Layout 1 - Wait 6 seconds set Layout 1 invisible ELSE Toggle group "Call Function ran" 1 Toggle Group Active"Call Function ran" 2 /call function "ran"/
(or whatever you choose to not collide with your random timing) * This way when the random Function calls Layout 1 again it will be invisible. I am guessing once the layout is gone it never comes back until the game resets)
**** TOGGLING THE GROUPS will prevent you from ever having both on or off at the same time.
System- Compare Two Values - Function.ReturnValue - Equals - 2 Layout 2 is visible / System - Go to Layout 2 - Wait 6 seconds set Layout 2 Invisible ELSE Toggle group "Call Function ran" 1 Toggle Group Active"Call Function ran" 2 /call function "ran"/
*Repeat this step for all layouts when the layout is set to invisible it will not be called because of these events and giving it the effect of being destroyed or at least unable to be called.

So you will have to create a lot of events if you have a lot of layouts but that is the simplest way I would go about doing it. If you understand arrays, parameters, or different types of variables you may find a quicker way to do this.

Doing these will pick a random return value every 'X' seconds and when the return value is selected it will go to layout number 'whatever' and then when the next 'X' seconds passes you will have made an action 1 second longer than the X seconds so that the previous layout goes invisible and since in the one event you put Layout 'whatever' is visible even when the random event is called it won't go to an invisible layout. ** The worst result is that a layout might be on the screen longer when you toggle the groups active and inactive, but at least you should never get invisible layouts.

**Make sure you space out everything apprpriately. You should get how I am thinking it's pretty simple then be able to adjust the seconds between accordingly. God bless you!
B
18
S
8
G
1
Posts: 56
Reputation: 2,018

Post » Mon Jun 01, 2015 8:11 am

hello
thank you very much for your long message. Now I'm at work but when I can try i tell you that this has gone.
B
5
Posts: 34
Reputation: 295


Return to How do I....?

Who is online

Users browsing this forum: amazingdream and 24 guests