4 Replies Latest reply on Feb 1, 2016 9:10 PM by jbell2355

    Guessing Game

    jbell2355

      I have a simple guessing game app I would like to create.   This app will be used by someone working to match names with faces.  It will look something like the following:

       

      Database Structure: ID, First Name, Last Name, Picture Container Field.  It will include standard utility fields along with a field utilizing the RANDOM Function to allow the sort to be varied. 

       

      The flow of what I would like is the following:

       

      Mock up.PNG

       

      The user will look at the picture and click on the corresponding button with the correct name.  If the person selects the correct name it will congratulate the user and move to the next record.  If it is incorrect they would receive a Custom Dialog informing them their choice was incorrect. 

       

      My thoughts so far are along these lines, but if there is a sample solution or other post please direct it to me.  I am not particular on how the mechanics, but these are my thoughts so far:

       

      Using the random function have every record have an integer ranging from 1-3.  Utilize this integer to know which button to populate the correct response button.  The other two would be selected at random from the remaining values in the database.  I just have not been able to wrap my head around how to make it come together. 

       

      Your responses and help is greatly appreciated. 

       

      FYI, I currently develop in FMP 13 Advanced.

        • 1. Re: Guessing Game
          ErikWegweiser

          Greetings:

          Assuming you're in your PEOPLE table and want to first go to a random record,

          show the picture, and a list of three names, two of which are incorrect...

          Try steps in your script like this:

           

          ## Sets the correct random button

          Set Variable $$correct_button to 1 + Int( Random * 3 )

           

          ## Goes to three random found records

          ## Chooses two incorrect names and lands on the name to guess

          Set Varable $found_count to get(foundcount)

          Set Variable $random_person to 1 + int( Random * $found_count )

          Go to Record by Calculation ($random_person)

          Set Variable $wrong_name_1 to PEOPLE::Full_Name

          Omit Record

           

          Set Varable $found_count to get(foundcount)

          Set Variable $random_person to 1 + int( Random * $found_count )

          Go to Record by Calculation ($random_person)

          Set Variable $wrong_name_2 to PEOPLE::Full_Name

          Omit Record

           

          Set Varable $found_count to get(foundcount)

          Set Variable $random_person to 1 + int( Random * $found_count )

          Go to Record by Calculation ($random_person)

          Set Variable $correct_name to PEOPLE::Full_Name

           

          If( $$correct_button = 1

               Set $$button_label_1 to $correct_name

               Set $$button_label_2 to $wrong_name_1

               Set $$button_label_3 to $wrong_name_2

          Else if $$correct_button = 2

               Set $$button_label_1 to $wrong_name_1

               Set $$button_label_2 to $correct_name

               Set $$button_label_3 to $wrong_name_2

          else

               Set $$button_label_1 to $wrong_name_1

               Set $$button_label_2 to $wrong_name_2

               Set $$button_label_3 to $correct_name

          end If

           

          Go to layout, stop or pause to wait for button click.

           

          In your layout, use the $$button labels for your buttons,

          with each button running a button click routine, passing

          the button number as the parameter (1, 2 or 3).

          Your button click routine simply checks

          to see if the button clicked = $$correct_button.

          • 2. Re: Guessing Game
            siplus

            Very interesting problem, will post an idea soon.

            • 3. Re: Guessing Game
              siplus

              OK, here is my take. Loved to code it

               

              see attached.

              • 4. Re: Guessing Game
                jbell2355

                Siplus and Erik,

                 

                Thank you for your responses.  The code from Erik was exactly what I was looking for.  I was 80% there in my head, but I couldn't get it out into code.  Thank you both for helping me not bang my head on the keyboard all night.  Also Siplus, thanks for the code!  I am sure I can incorporate some of it into my project as well, as it did exactly what I was looking for.  It was exciting to see what I had envisioned for my app right before my eyes.

                 

                Thanks again ErikWegweiser and siplus