How to Toggle something with click or key-press?

This forum is currently in read-only mode.
From the Asset Store
High quality sound effect pack, in the following categories: Simple, negative, pozitive
  • How can I make that only one of the two actions is executed each time, instead of instantly executing both at the same time?

    See .cap

    It's the same with Mouse or Keyboard, that's why I put both, to see how each one can be fixed.

  • You can use condition "Else" from "System" - just put this condition as event below event you want have else-d. I don't have Cons right now so can't see CAP.

    Event Key "K" pressed : set Value to (Value + 1) % 2

    -> SubEvent "Value = 1" : some actions

    -> SubEvent "Else" : action if Value NOT = 1

    Something like this should solve toggling.

  • It's a common problem. BROO is right, use ELSE to fix it. The reason your current application doesn't work is because events and triggers run in top to bottom order. The first trigger sets the animation frame to 1. The second trigger tests if it's on animation frame 1 (which it is, it just got changed to it) and as a result changes it straight back to 2. ELSE ensures only one action happens per trigger, which fixes it.

  • ELSE ensures only one action happens per trigger, which fixes it.

    All right... I learned something today

    I've been doing my switch toggles since before Else came out, and never bothered to rethink how to do it. Old habits die hard, I guess.

  • Alright... that worked.

    But what If I want to have more than two actions?

    EDIT: Nevermind, got it.

  • Again, I can't do it right.

    I want something as simple as this:

    • Click on object

    If 1, set to 2

    If 2, set to 3

    If 3, set to 1

    Variables, animation frames, whatever.

    Also, If I click on something to take me to the next layout, and on that layout I have something on the same position as the previous object also with an action set when is clicked, that action happens immediately.

    This even happens when I set "Button is released" instead of "On click".

    Please help me, I'm kinda sick of being stuck with something this simple to make the menu for my game.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • http://upload.namelezz.net/downloader.p ... button.cap

    Push the button, the % means modulo.

  • (Don't have Cons now, can't see CAP)

    When making menu (for example with 4 options: 0, 1, 2, 3), you'd probably have something like this:

    -> "UP" pressed: set value to (value - 1) % 4
    -> "DOWN" presset: set value to (value + 1) % 4[/code:emvn93xm]
    Since I didn't know how program deals with modulo of negative number, I did tend to do it this way:
    [code:emvn93xm]-> "UP" pressed: set value to (value + 4 - 1) % 4
    -> "DOWN" presset: set value to (value + 1) % 4[/code:emvn93xm]
    Maybe I'm oversensitive on this stuff, but I don't want have surprising results ^^.
  • Since I didn't know how program deals with modulo of negative number, I did tend to do it this way:

    -> "UP" pressed: set value to (value + 4 - 1) % 4
    -> "DOWN" presset: set value to (value + 1) % 4[/code:3onoiwue]
    hy not just 
    -> "UP" pressed: set value to (value + 3) % 4
    -> "DOWN" presset: set value to (value + 1) % 4[/code:3onoiwue]
    Little error with really decoration problem   , also i made almost the same thing but only with adding.
  • Writing "4-1" provides information about "why this is 3?". You can say it's a calculation that documents code. When performance isn't vital in algorithms, I'd rather try to make code easier to understand.

    It'd be the best if you created some sprite called "Conf" and put PV like "ElementsCount" and then done events like:

    -> "UP" pressed: set value to (value + Conf('ElementsCount') - 1) % Conf('ElementsCount')
    -> "DOWN" presset: set value to (value + 1) % Conf('ElementsCount')[/code:1cjhwone]
    This'd be more flexible and useful for next appliactions.
  • Writing "4-1" provides information about "why this is 3?". You can say it's a calculation that documents code. When performance isn't vital in algorithms, I'd rather try to make code easier to understand.

    FYI, the runtime will simplify a constant expression (eg. 4 - 1 to 3) on startup, so you can always do this to make your expressions clearer without suffering any performance hit.

  • Thanks, that modulo thingy sure was helpful.

    Now I just need a solution for my 2nd problem and I won't bother you guys for a while

    Also, If I click on something to take me to the next layout, and on that layout I have something on the same position as the previous object also with an action set when is clicked, that action happens immediately.

  • Also, If I click on something to take me to the next layout, and on that layout I have something on the same position as the previous object also with an action set when is clicked, that action happens immediately.

    That sounds like something that should be fixed in Construct itself. As a workaround, you could set a variable in the Start of Layout that sets value"clicking" to "off" or something like that. Then in the events for your button clicks, add a condition that checks the status of the variable. After your button click events, set the variable to "on." That should work.

    Kind of a hacky workaround, but hey, it should get the job done.

  • That sounds like something that should be fixed in Construct itself. As a workaround, you could set a variable in the Start of Layout that sets value"clicking" to "off" or something like that. Then in the events for your button clicks, add a condition that checks the status of the variable. After your button click events, set the variable to "on." That should work.

    Kind of a hacky workaround, but hey, it should get the job done.

    Lol, I was just trying that.

    And yes, it looks like it's working so far!

    But, anyway, it still is kinda lame that we must have this kind of workaround for something that should be simpler.

    Thanks to everyone who helped me

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