Use One Condition to Check Multiple Things [C2] [SOLVED]

0 favourites
  • 3 posts
From the Asset Store
A cool way for kids to write and practice English Alphabets
  • Hello, all.

    I'm looking for a C2 algorithm for 1 condition on key press that could check 4 things.

    I have 4 elements/sprites.

    "story so far"

    "continue"

    "start a new game"

    "controls"

    They blink on auto in sequence as selections.

    Currently I have this setup:

    if button is pressed (say XPAD D-pad up):

    if anim "blink" in "story so far" is playing:

    <-- set anim "default" in "story so far"

    <--set anim "blink" in controls

    2 other conditions for the other elements

    if anim "blink" in "controls" is playing:

    <-- set anim "default" in "controls"

    <--set anim "blink" in "story so far"

    **This ends up executing 2 conditions because of the resets as opposed to 1**, (1 exclusive condition check is what I need), so the list never goes to the last element.

    I'm guessing this is a pretty common problem in programming, so the solution is just having 1 condition check on key press which checks 4 things?

    No idea how to program this.

    I'm guessing something with pushback array, etc.?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You don't need arrays..

    You can use a simple variable MenuSelected (which stores a number id or a text tag of the button) and, say, a function that will set "Blink" animation for the selected item and "default" for others.

    On button Up pressed -> 
       set MenuSelected to Max(1, MenuSelected-1)
       Call Function UpdateMenuButtons()
    
    On button Down pressed -> 
       set MenuSelected to Min(4, MenuSelected+1)
       Call Function UpdateMenuButtons()
    
    On Function UpdateMenuButtons
       MenuButton -> Set animation to "Default"
       Pick MenuButton with id=MenuSelected -> Set animation to "Blink"
    [/code:3dllbdl8]
    
    If you prefer working with string tags, this expression may be handy to minimize the number of events:  
    (condition ? result_if_true : result_if_false)
    
    .....set MenuSelected to (MenuSelected="controls" ? "start" : (MenuSelected="start" ? "continue" : (MenuSelected="continue" ? "story" : "controls")))
  • Thank you.

    That's very interesting.

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