How to make a sprite disappear by pressing buttons in correct order?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Radgrid728

Is there any way to make a sprite disappear by pressing buttons in correct order?
For example, there are 1~5 buttons and when you press button1, button2, and button3 in order a sprite disappears.

:bust_in_silhouette: Reply From: magicalogic

This is how I would do it .

  1. Have an array to hold the button presses in order. Nothing too complicated, just integers indicating button numbers. This should be global.
  2. Connect the pressed signal of each button to the same function while passing a custom varible carrying the button number.
  3. The function then adds the value of the custom varible to the array holding button presses.
  4. Declare another global array holding a sequence of button presses which should triger the hiding of the sprite. The sequence is just a list of numbers.
  5. This triggering array is compared with the first array in the function connected to the pressed signal of all buttons and if they match, I hide or queue free the sprite.

If this is the behavior you are trying to create but you have problems implementing it in code, comment below.