[SOLVED] Random Layout, does not work :(

0 favourites
  • 7 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • 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:

    scirra.com/forum/can-the-system-randomly-select-the-next-layout_topic43927.html

    I have made these actions and events:

    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...

    Here, the image:

    <img src="http://oi49.tinypic.com/2cerepz.jpg" border="0" />

    But as I said, this does not work.

    A greeting and thanks.

  • hello, all the compare event (rd=1, rd=2 , ...) have to be a sub event of the "On start of layout" event

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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:

    <img src="https://dl.dropboxusercontent.com/u/14522925/C2%20examples/sub-events.jpg" border="0" />

  • Thanks Mimiste <img src="smileys/smiley2.gif" border="0" align="middle" />

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

    <img src="http://oi46.tinypic.com/r73j9v.jpghttp://" border="0" />

    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.

  • 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.

  • I was going to mention that but I saw that he rounds it off, so I think he's aware of it.

  • Now, it works ^ _ ^

    The final image to another user with the same problem:

    <img src="http://oi50.tinypic.com/hva0r5.jpg" border="0" />

    Thanks to all who have answered me.

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