PDA

View Full Version : [SOLVED:] Color Combination Sequence Game



pching
04-13-2021, 10:24 PM
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!

Paul_Hossler
04-15-2021, 11:09 AM
Attaching a small presentation with (say) 2 slides and your macro would be more helpful

pching
04-15-2021, 09:53 PM
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.

Paul_Hossler
04-16-2021, 06:04 PM
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

pching
04-16-2021, 10:09 PM
Paul, that worked perfectly! Thanks so much for your help. I'll tweak it to fit my desired color sequence.

Paul_Hossler
04-17-2021, 08:16 AM
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

pching
04-18-2021, 05:41 PM
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!