Search Unity

Logic Problem with Buttons

Discussion in 'Scripting' started by MoonJellyGames, May 24, 2019.

  1. MoonJellyGames

    MoonJellyGames

    Joined:
    Oct 2, 2014
    Posts:
    331
    Hi all. I've started working on an unofficial port of a tabletop game (for my own personal use), so I don't think I can get into the detail of it, but that shouldn't be necessary for the problem I'm having.

    Basically, I have sequences of buttons in different configurations. Most buttons have a "next" operator between them, indicating that pressing one should enable the next, however the game also makes use of an "or" operator which complicates things. This seems just like one of the search problems I've written code for in programming and algorithm classes before, but I just don't remember. The only wrinkle is that unlike those problems, my branches can merge (see second diagram).

    It seems as though I'll need to use a three dimensional array, but it feels like there might be a better way.

    There needs to be a list/array that contains the entire tree of buttons. I've whipped up some lovely MS Paint diagrams to hopefully make it clearer what I'm after:

    Here's a super basic example:


    And a more complex example:


    So, there's a Button, a ButtonSequence (list of one or more buttons), and a ButtonSequenceSet (list of one or more ButtonSequences).

    This probably goes without saying, but the buttons do more than just disable/enable other buttons. They indicate the next action the player will take, then they'll take that action, and once it's finished, the GameManager will tell the objecting containing the above-mentioned ButtonSequenceSet that the action is completed, and the buttons will be displayed again for the player with the appropriate ones enabled/disabled as described.

    These sequences don't usually get too deep (I think one nested "or" is the deepest I've seen), but I want to make this in a way that I could accommodate for future expansions.

    I hope that was clear enough and that somebody out there is willing and able to explain a good way to handle this. I suspect that I could just do it my own way and it would work, but that's how I ended up with a super tedious-to-adjust menu system in my last game.

    Thanks!
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    MoonJellyGames likes this.
  3. MoonJellyGames

    MoonJellyGames

    Joined:
    Oct 2, 2014
    Posts:
    331
    Thanks for the response! I actually came up with a solution which, incidentally, is pretty much what that link describes. :)
     
    GroZZleR likes this.