Yay! I did it!

Okay, so I managed to get it working as requested.

Haven’t checked the Ben’s way of doing it yet, but must confess, had a quick browse through the other comments here and got a big clue as to where the passwords should be set!

Apologies, I can’t post my exact code as I’m terrible for using expletives all over the place - you don’t want to know what my passwords were!!! But essentially,

  • I created a new string variable called password up at the top in the Game State stuff

  • In the RunMainMenu function, I set password to be one of two words, depending on whether the user picked level 1 or 2. Looking at my code I can see this possibly is a bit of duplication - I could probably have come up with a way of picking the password by setting up all the possible passwords in a variable ( well, i’d refer to it as an array - but we haven’t covered those yet. I’ve used arrays in my limited experience with another programming language, as to my mind - the enum bit we covered earlier looks and behaves like what I’d consider to be an array, so waiting to learn more in case there are technical differences that I just don’t understand yet!)

  • I added another ‘else if’ in the OnUserInput function to check if the currentScreen ==Screen.Password and if it was then I told it to run a function called Result and send over the input - Result(input)

  • Finally, I actually created the function Result in which I checked if the player input matched the password, then with another if…else routine,

if (input==password)

Then depending on their input I either congratulated the player for getting it right, or rudely told them they got it wrong and should try again!

That last section actually caused me a problem as initially I put it in as

void Result(input)

instead of

void Result(string input)

I’m having trouble remembering that if you’re receiving a variable from another function that you have to put the type in!

I almost completely overdid things by thinking that in the Result function I’d have to break down the result and check what the level was and build a complicated matrix of outcomes - i.e.

if the level is 1 and the input equals the right password for level 1, etc, then I realised that I didn’t have to . I’d already set the password variable earlier, I just need to check if the input matched or not.

So, I did enjoy this challenge. I’m carrying the legacy of having spent the last few years using the built in programming language within the GameMaker Studio game engine. While it does utilise functions, it doesn’t exactly present them to the user in the way you see them in a c# script. So, I’m having to unlearn a few things in order to get my head around these new things I’m learning!

Update!

Hey, I smashed it! Ben’s code was pretty much the same as mine! And the next video is about arrays. For now, I’m allowing myself to feel a tiny bit smug! But not too smug!!!

Onwards I go!

1 Like

Privacy & Terms