Consulting

Results 1 to 7 of 7

Thread: Color Combination Sequence Game

  1. #1
    VBAX Newbie
    Joined
    Apr 2021
    Posts
    4
    Location

    Exclamation Color Combination Sequence Game

    Hello everyone!

    I am in the process of making a PowerPoint Escape Room for an organization I'm in, and I've tried getting my feet wet in VBA to add interesting and complex puzzles to it.

    I need help getting one such puzzle to work.

    Simply put, clues would lead the players to come to the conclusion that they would need to input a Red-Gold-Green-Gold sequence into a pad of circles under a globe, at which point the globe would provide them a key to unlock a door. I have it set up where there is a palette of four colors off to the side that they click, and once they select a color from the palette, they click the respective circle that they want to fill with that color.

    Here's the code for everything I've talked about so far:

    Dim RGB As Variant

    'player selecting the color
    Sub ChooseColor(oSh As Shape)
    RGB = oSh.Fill.ForeColor.RGB
    End Sub

    'player filling the circle with the color
    Sub CircleColor(oSh As Shape)
    oSh.Fill.ForeColor.RGB = RGB
    End Sub

    For its intended purpose, the above code works perfectly for me.

    My question now is: is there a way that if each circle was the correct color, the presentation would move onto the next slide?

    Below is my unsuccessful attempt at this:

    Dim firstColorCorrect As Integer
    Dim secondColorCorrect As Integer
    Dim thirdColorCorrect As Integer
    Dim fourthColorCorrect As Integer
    Dim oSh As Shape
    Dim oSl As Slide


    Sub GlobeKey()
    If oSh(1).Fill.ForeColor.RGB = RGB(255, 0, 0) Then firstColorCorrect = 1
    If oSh(2).Fill.ForeColor.RGB = RGB(255, 192, 0) Then secondColorCorrect = 1
    If oSh(3).Fill.ForeColor.RGB = RGB(0, 176, 80) Then thirdColorCorrect = 1
    If oSh(4).Fill.ForeColor.RGB = RGB(0, 112, 192) Then fourthColorCorrect = 1
    If firstColorCorrect + secondColorCorrect + thirdColorCorrect + fourthColorCorrect = 4 Then ActivePresentation.SlideShowWindow.View.Next
    End Sub

    I have the GlobeKey macro set onto an "Enter" button that I've placed below the circles.

    I've attached a screenshot of the slide, just so you can see what everything looks like from a non-VBA standpoint.

    Thank you in advance for your help!
    Attached Images Attached Images

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Attaching a small presentation with (say) 2 slides and your macro would be more helpful
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Newbie
    Joined
    Apr 2021
    Posts
    4
    Location
    Hi Paul,

    I've attached the two slides in question. You'll see three macros total: ChooseColor, CircleColor, and GlobeKey. ChooseColor works, and it is for when you click the colored square to select a color; CircleColor works, and it is for after you've selected a color and you click a circle to fill it with the color; and GlobeKey is the macro where theoretically when the players click the Enter button and the four circles are filled with the correct colors (the 1st circle should be RGB(255, 0, 0), the 2nd circle should be RGB(255, 192, 0), the 3rd circle should be RGB(0, 176, 80), and the 4th circle should be RGB(255, 192, 0) - the 4th circle here is different than my initial post because I made a typo with the wrong color!), they would progress to the next slide.
    Attached Files Attached Files

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Probably 100%, but you can take a look at this

    To initialize everything, I had to add a "Click to Start" button on the first slide

    The 'correct answers' I put on the top left corner of slide 2 and 3 so I could remember -- delete them for production
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    VBAX Newbie
    Joined
    Apr 2021
    Posts
    4
    Location
    Paul, that worked perfectly! Thanks so much for your help. I'll tweak it to fit my desired color sequence.

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Glad it worked

    If the concept is OK, then if there's a lot of slides, I'd suggest changing the way correct answers are stored to make data entry and maintenance easier

    Maybe something like this which uses slide tags

    Option Explicit
    
    
    Public Const colRed  As Long = 255
    Public Const colGold As Long = 49407
    Public Const colGreen  As Long = 5287936
    Public Const colBlue  As Long = 12611584
    
    
    Public colPicked As Long
    
    
    Sub StartTest()
        Dim oSlide As Slide
        
        With ActivePresentation
            .Slides(2).Tags.Add "Answer", "ROGB"        '   O = Gold
            .Slides(3).Tags.Add "Answer", "BROG"        '   O = Gold
        End With
    
    
        For Each oSlide In ActivePresentation.Slides
            With oSlide
                If .SlideNumber > 1 Then Call AllBlack(oSlide)
            End With
        Next
    
    
        ActivePresentation.SlideShowWindow.View.Next
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  7. #7
    VBAX Newbie
    Joined
    Apr 2021
    Posts
    4
    Location
    Hi Paul, you seem to have read my mind. I was actually just about to ask you how I could adapt the code for a larger presentation. Using your suggested changes, I was able to make it work with the correct respective slide numbers. Thanks again for your help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •