I just started using Adventure Creator and have the basics down, but now I want to create a puzzle where the player has to call a number from a telephone. So I want the player to press eight buttons on the phone in the right order to trigger a cutscene, if they press the wrong eight buttons I just want to trigger an error sound.
My brain breaks when I try to think about figuring out how to do this, could anyone point me in the right direction?
Thank you!
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Declare an int variable called "Presses" to record how many times the player has pressed a key, and a string variable called "Number" to record the number the player is dialling.
Whenever the player clicks a button, add 1 to Presses and check if Presses equals 8.
If Presses equals 8, append the number of the button pressed by the player to the Number string, and then check if Number equals the correct number. If so, set Presses to 0 and trigger the cutscene. If not, set Presses to 0 and play the error sound.
If, after clicking the button and adding 1 to Presses, Presses does not equal 8, check if Presses equals 1. If it does, set Number to the number of the button pressed by the player. If it does not, append the number of the button to the Number string.
Similar idea, but I think you could get away with just one Integer variable used to track the "score", instead of which specific numbers were pressed.
Let's say the number is 0457, and we have an Integer named "Score" which is zero at the start of the puzzle.
If we start by pressing "0" (the first digit of the telephone number), that's correct - so long as our Score is currently zero. In which case, increase Score to 1.
If we press "4", that's only correct if Score = 1, in which case Score now = 2. Otherwise, reset it to Zero.
Basically, for each button, run a Variable: Check Action that checks the Score value necessary for that button to be valid. If it is, use Variable: Set to increase Score by 1. Otherwise, set it to 0 to reset the puzzle.
Good thinking! It's true that you don't need to save the numbers dialled to a string variable, but I think you still need a second integer to count the number of presses, or else the error message can't be delayed until after the player has pressed 8 buttons.
I'd probably mix my method with yours - I'd keep a Score integer instead of saving the numbers to a string, but I'd only check against it once the buttons had been pressed 8 times.
Yes, good point - if you want to wait until all digits have been entered before giving a result, you would need to have a separate variable that counts the number of buttons you've pressed.
Thank you for your answers! Both helped me figure out a way to do it - sort of.
Chris solution is good, but from what I understand it would only work if there are no double numbers?
I have come very close to getting it to work, I just don´t know how to append a number to a string.
I might have complicated things but this is how I built it:
integer - presses '0'
string - correct number '0408724731'
string - current number ''
and then a string for each number: 0-9
When a button is pressed increase "presses" by one, then I want to append the string of the button pressed to "current number", check if "presses" = 8, if met play a dial tone, then check if "current number" = "correct number", if met play the cutscene.
So all I´m missing is how to add a string to another string, if that is possible?
Thanks for your patience with a logic rookie.
You don't need a string for each number! You just need to use the action "Variable > Set > Combined With Other String", and then enter the number you want to add in the "Statement: +=" field.
For future reference though, Chris' method CAN work with double numbers. You just need to chain if statements. For example, check if presses = 1; if true, add 1, and if false, check if presses = 2, etc.
The advantage of using a score integer is that in my opinion integers are simpler to deal with. The advantage of using a string for the dialled number is that then you can easily built upon it if necessary (you can add more correct numbers to call different people, or change the solution entirely, without ever having to touch the buttons' logic again) - this isn't possible with a score integer because the solution is baked into the buttons.
Thank you so much! The HoloPhone is now working exactly how I wanted it to.