Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Gabarts on Fri 10/01/2014 12:25:15

Title: More on Puzzle-Design
Post by: Gabarts on Fri 10/01/2014 12:25:15
Question for advanced programmers or game creators:

Suppose you need to design a standard puzzle as seen in many games, like for example a 5 digit-code to open a door or like in Last Crusade, a skull-organ to play to open the passage...

Ok, I can do single sprites for the objects to click that I can animate and each object will have a condition.
What kind of code you would use? Where to start... just the basics to start making this kind of puzzle.

I'm using the M9 verb, that one with function_item_AnyClick(); and verbs

Thanks
Title: Re: More on Puzzle-Design
Post by: Andail on Fri 10/01/2014 13:15:12
Let's say you need to click four buttons in the correct order to open the door.
The buttons are:
A    B    C    D

And the right combination is
C    D    A    B

What you need to do now is declare an int, that we call "code."
Before any buttons are pushed, code is 0.
(at the top of room script)
int code;

Then you just start adding conditions.

For button C:
if (code == 0) code ++;   //increase "code" by one
else code = 0;   // otherwise reset "code"

For button D:
if (code == 1) code ++;
else code = 0;

For button A:
if (code == 2) code ++;
else code = 0;

For button B:
if (code == 3) code ++;
else code = 0;

So, whenever a button is pushed when it's not supposed to, the mechanism will be reset. If you keep pushing the buttons in the right order, the integer will increase.

You can use the repeatedly_execute to decide what will happen as soon as "code" is 4.
Title: Re: More on Puzzle-Design
Post by: Khris on Fri 10/01/2014 15:34:19
Or just unlock the door here:
Code (ags) Select
  // button B
  if (code == 3) unlock_door();
  else code = 0;
Title: Re: More on Puzzle-Design
Post by: Gabarts on Fri 10/01/2014 23:04:33
Nice :)

Thanks for this, I will try...

Ah, would be nice to add also a custom animation in case of wrong combination, in that case I need to assign the sprite view loop when code = 0?