issue with key doing two different things (conditionally)

This forum is currently in read-only mode.
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • so i have a button that i want to use as 'catch ball' and 'pass ball'. you can't pass a ball unless you have a ball. you can only catch a ball if you don't already have one.

    but about half the time when i catch a ball, it will automatically pass it at the same time. i do have it set to 'when control pressed' and not 'when control is down' (and FYI, they are different controls but listed as the same key). i could understand if it always passed (and re-ordering events would probably be enough to fix)... but oddly enough it seems to choose what it will do randomly (seems to be equal chance of doing either). any tips on how i could easily fix this? i can think of ways but they're more cumbersome than i'd like -- and hey, i usually learn new shortcuts when asking questions .

    edit: weird.. it's literally like alternating between the two. even if i change layouts and go back to the gameplay layout. it's not random... it's just alternating between the two.

  • Well, without looking at the .cap I can only guess what's going wrong... but I would assume that it's because of the order of events. When you have two "On control pressed" triggers in one tick, they both will trigger. So if you have:

    +On control "Ball" pressed
      ->Catch ball
    
    +On control "Ball" pressed
      ->Pass ball
    [/code:2s95oxjz]
    
    then both action 1 and 2 will trigger.  You might have to structure it like so:
    
    [code:2s95oxjz]
    +On control "Ball" pressed
      +value('hasBall') is equal to "true"
        ->Pass ball
      +Else
        ->Catch ball
    [/code:2s95oxjz]
    
    That way you're only doing one control check, but depending on the sub-events there could be two different outcomes.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • well it's more like this

    +On control "p1_catch" pressed
      ->Catch ball
    
    +On control "p1_pass" pressed
      ->Pass ball
    [/code:3la0rcfr]
    
    both controls are mapped to the same key though.*  but [b]half[/b] the time, it will catch and immediately pass the ball, but the other [b]half[/b] of the time, it will only catch the ball.  if it auto-passed it last time, it will just catch it -- and if it only caught it last time, it will auto-pass it the next.  this pattern of alternating back and forth continues even if i go to main menu layout and back to gameplay layout, but i don't use global variables for these, either.
    
    *i chose to use two different controls because, in the future, i plan to implement customizable controls -- default control scheme will have them on the same key/button.
  • +private.variable = 0

    +On control "p1_catch" pressed

    ->Catch ball

    ->set private.variable to 1

    +private.variable caught =1

    +On control "p1_pass" pressed

    ->Pass ball

    ->set private.variable to 0

  • +private.variable = 0

    +On control "p1_catch" pressed

    ->Catch ball

    ->set private.variable to 1

    +private.variable caught =1

    +On control "p1_pass" pressed

    ->Pass ball

    ->set private.variable to 0

    i'm already doing something similar, but with testing for 'is animation playing' rather than private variables. you'd have to switch the order in your example though, or it'd always fly through both (the order of mine apparently doesn't matter, because either way it still does it half the time).

    the odd behavior is that it only auto-passes half the time.

    edit: if it makes any difference, i'm using Functions for the actual actions.

  • what's the simplest way i could implement a delay after you catch it before you could pass it? hopefully something simpler than creating a variable and have it count down... i just need it to not let you pass it immediately. seems like a 'wait a tick' action would be useful

  • Well you said your using animation playing... how long's the animation?

  • Well you said your using animation playing... how long's the animation?

    right now just placeholder 1 frame animations showing whether the ball is behind held or not, but yeah i think your idea will probably work.

    thanks

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