help with selecting a subset of options

jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408

I've been working on this for a few days, and there has be an easier way of doing this. My code should work, but it doesn't. In my game I present the user with 6 options. They can select and deselect them at will. This part works fine. The problem is, I only want 3 of the options to be selected at any time. So if the user selects options 1, 2, 4. They would have to deselect one of them to choose option 5. On top of that, I need to keep track of the values of each option.

I've tried storing the values in attributes and tables. but for whatever reason my deselect code never seems to function properly. the image will show it deselected, but the back end attribute doesn't update.

I know this is easy, but I have a feeling I'm getting too caught up with my existing code to see the answer staring me in the face.

Anyone done something similar before?

Comments

  • quantumsheepquantumsheep Member Posts: 8,188

    Have a 'selectable' variable - set it to 0.

    When you select an option, add 1 to 'selectable'.

    When you deselect an option, subtract one.

    When selecting an option, have the rule:

    If not selected
    And
    If 'selectable' is less than 3
    And
    Touch is pressed

    Then select the option.

    Hope that helps/points you in the right direction :)

    QS =D

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    edited October 2014

    for example, this is some of my code. In both examples it compares the value of the first slot with the value of the option selected. If they match, it makes the change, otherwise it moves down the list.

    buttonState = 1 means option is selected
    buttonState = 0 means option is not selected
    
    
    if buttonState = 1  
      if game.slot1 = 0
      set game.slot1 = self.itemnumber
        otherwise
        if game.slot2 = 0
        set game.slot2 = self.itemnumber
          otherwise
          if game.slot3 = 0
          set game.slot3 = self.itemnumber
    

    and to clear it

    if buttonState = 0   
      if game.slot1 = self.itemnumber
      set game.slot1 = 0
        otherwise
          if game.slot2 = self.itemnumber
          set game.slot2 = 0
          otherwise
            if game.slot3 = self.itemnumber
            set game.slot3 = 0
    
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408

    @quantumsheep said:
    Have a 'selectable' variable - set it to 0.

    When you select an option, add 1 to 'selectable'.

    When you deselect an option, subtract one.

    When selecting an option, have the rule:

    If not selected
    And
    If 'selectable' is less than 3
    And
    Touch is pressed

    Then select the option.

    Hope that helps/points you in the right direction :)

    QS =D

    hrm, good idea. I'll have to see how it will against keeping track of the values, but it could work!

  • quantumsheepquantumsheep Member Posts: 8,188

    @jonmulcahy said:
    hrm, good idea. I'll have to see how it will against keeping track of the values, but it could work!

    Remember to save every time you select/deselect (as in, save which options are selected/deselected and save the 'selectable' value).

    You should be fine ;)

    QS =D

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408

    @RThurman said:
    jonmulcahy‌ -- the demo found here might be useful:

    http://forums.gamesalad.com/discussion/comment/496956/#Comment_496956

    I thought of something like that, but that acts as a first in first out selection method. I wanted the users to be able to choose 1,2,3, then deselect 2 and select 4.

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    edited October 2014

    this is so frustrating. I changed my code completely, and it still is freaking out.

    I now have a table with 6 rows, 1 for each option. when you touch a button, it changes it's row to 1. I have a rule that takes the sum of the table, and only allows you to select an option if it is less than 3. this works fine. however when I try to add the code to remove the option, i get a dual trigger. It adds and removes the last entry instantly.

    what a PITA!

     when touch is pressed
          when tableColSum(game.table) < 3
               change table value
                    table: game.Table
                    row: self.optionNumber
                    Col: 1
                    value: (tableCellValue(game.Table,self.OptionNumber,1)+1)%2
    
          when tableColSum(game.table) = 3
          AND
          tableCellValue(game.Table,self.OptionNumber,1) = 1
               change table value
                    table: game.Table
                    row: self.optionNumber
                    Col: 1
                    value: (tableCellValue(game.Table,self.OptionNumber,1)+1)%2\
    

    I've tried moving them into separate touch rules, switching to on release, putting timers in there, etc. but it keeps double firing.

    the idea is that as long as the total value is under 3, they can select a new value. If the value is 3, they can toggle ONLY an option they have previously selected, changing it back to 0. but in the case above, that drops the total value to under 3, and it toggles the same value back to 1.

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    edited October 2014

    well i feel stupid. one simple change and all my problems are solved:

       when touch is pressed
            when tableColSum(game.table) < 3
                 change table value
                      table: game.Table
                      row: self.optionNumber
                      Col: 1
                      value: (tableCellValue(game.Table,self.OptionNumber,1)+1)%2
    
          OTHERWISE
    
           when tableCellValue(game.Table,self.OptionNumber,1) = 1
                change table value
                     table: game.Table
                     row: self.optionNumber
                     Col: 1
                     value: (tableCellValue(game.Table,self.OptionNumber,1)+1)%2
    
  • quantumsheepquantumsheep Member Posts: 8,188

    Glad you got it working :)

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited October 2014

    I was going to say use a mod function I see you did that.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881

    @jonmulcahy said:
    I thought of something like that, but that acts as a first in first out selection method. I wanted the users to be able to choose 1,2,3, then deselect 2 and select 4.

    It has deselection stuff in there as well Give it a try! Do the exact sequence you outlined above and it will deselect 2 and then select 4.

Sign In or Register to comment.