Much trouble with global variable. Can help?

This forum is currently in read-only mode.
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • I create Global variable before for game timer and it work perfect. Now I try to make global variable for menu but have much trouble.

    My menu screen have a XBOX 360 controller icon (C1) in middle of menu. When user push left on left analog stick, the icon move to the left. When the user press right the icon moves back to the right.

    The left side of the screen has a boundary, and the right has a boundary.

    When the 360 control icon collide with left boundary it's supposed add 10 to global variable value.

    What I having trouble with is, I want the A button to be deactivated until and only when C1 collides with Left Boundary, so that state of collision is remembered and when A is pressed it will add another 10 to Global Variable equaling 20 and make game go to new layout. I have try several conditons and events but cannot get it to work. Right now, it goes to new layout if I just press A without colliding, or if I just collide with left boundary without pressing A it goes to layout.

    <img src="http://farm2.static.flickr.com/1121/4732437056_745454296e_b.jpg">

    Can you tell me what I do wrong in code? I much appreciate

  • Hi. I see a few problems there. First, I'll go into those. If I understand what you are trying to do correctly...

    • It appears that event 1 and 2 cancel each other. Construct will go right to event 2 after 1, and reactivate the controller because the stick will still be to the right. If you're trying to stop C1, just set the boundaries so that they have the 'Solid' attribute.
    • In event 3, it seems as though you want to set a state, so that you know what the player selected. But, by Adding 10 to the global variable while c1 is collided with LeftBoundary, your global reaches 20 in two frames, because it's still colliding on the next tick. It's better to Set the global variable to a certain value in this case.
    • In event 4, you are checking that button A is down, so it will be true every tick that the button is down. Since you are Adding to the global variable, once again, it will reach 20 in two ticks again. In this case, it would be better to check the state of the global variable in sub-events to the Button A is down check, and take your actions there.
    • Thus, event 5 should not be needed.

    Here is text version of the way I'd do the events:

    + C1: On collision between C1 and LeftBoundary
    -> System: Set global variable 'MenuSelect' to 1
    + C1: On collision between C1 and RightBoundary
    -> System: Set global variable 'MenuSelect' to 2
    + MouseKeyboard: On key Left mouse button pressed
        + System: Is global variable 'MenuSelect' Equal to 1
        -> System: Go to layout "1234" with transition "None" lasting 0 MS
        + System: Is global variable 'MenuSelect' Equal to 2
        -> System: Go to layout "Whatever" with transition "None" lasting 0 MS[/code:27a6rdlv]
    
    Note that the indented portion is two sub-events, and I used the Left Mouse Button instead of button A. This simply sets the global variable to either 1 or 2, depending upon which boundary is hit last (you can change your mind and hit the other,) and when the button is hit, it checks to see if one was selected, and goes to another layout based upon that choice.
    
    The quick example is here:
    
    [url]http://dl.dropbox.com/u/5868916/ExampleMenu.cap[/url]
    
    If I'm way off about what you wanted, you may need to explain in more detail, and post your .cap. Good luck.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It works so perfection! Using set value for global variable I failed consideration, now you have show me better way!

    Thank you much Silent Cacophony! I am grateful!

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