Coding a safe cracking puzzle. Is there an easier way?

Started by Durinde, Fri 24/02/2012 15:52:05

Previous topic - Next topic

Durinde

Any coding/scripting that I've ever done has been self taught, so I sometimes feel after coding something a certain way, that there may be an easier/quicker way.

I'm working on a test game right now to learn the various features of AGS. I wanted to make a safe cracking puzzle, so here's how I went about it.

First I set six global variables (3 pairs of ints and strings).
I also set a variable for how many numbers the player has correctly entered.

Here is the code.

{
if (scrack == 0) {
Num1 = Game.InputBox("First number");
Num1a = Num1.AsInt;
if (Num1a == 17) {
Display("You hear an audible click. Your first number must be correct.");
scrack = 1;
}
}
if (scrack == 1){
Num2 = Game.InputBox("Second number");
Num2a = Num2.AsInt;
if (Num2a == 7) {
Display("You hear an audible click. Your second number must be correct.");
scrack = 2;
}
}
if (scrack == 2){
Num3 = Game.InputBox("Third number");
Num3a = Num3.AsInt;
if (Num3a == 8 ) {
Display("You hear an audible click. Your third number must be correct. The safe is open!");
scrack = 3;
}
}
else
Display ("Nope, something isn't right.");
}

Is there a more efficient way of coding this?  I'm also planning on setting scrack back to 0 upon the player entering a wrong number in the sequence, making them start from scratch.

Atelier

Code: ags

function OpenSafe()
{
     String Num1 = Game.InputBox("First number");

     if (Num1.AsInt == 17) 
     {
               Display("You hear an audible click.");
               String Num2 = Game.InputBox("Second number");

               if (Num2.AsInt == 7)  {

                        Display("You hear an audible click. Your second number must be correct.");
                        String Num3 = Game.InputBox("Third number");

                         if (Num3.AsInt == 8) {
                             Display("You hear an audible click. The safe is open!");
                             //show safe GUI or whatever
                        }
                        else Display("You got the third number wrong. Start again.");
               }

               else Display("You got the second number wrong. Start again.");

    }

    else Display("You got the first number wrong. Start again.");

}


Call the function when the player interacts with the safe, which will mean they can enter again if they get any of the figures wrong.


DutchMarco

Sorry to be so offtopic (BTW the code does look elegant!
But I do question the wisdom of resetting the lock at every mistake. That's just frustrating, and the player already has the numbers, right? So why not make use of the fact that this is a game and magically put/keep the numbers correct?

Durinde

I think I was looking back to my high school days when I had to start from scratch if I messed up the combo for my locker. Part of the reason was I wanted to have the experience scripting it like that. Is it poor game design on my part? Absolutely.

I think if I were to actually have a safe combination in a game, I'd probably go with a interface similar to what was used in 6 days a sacrifice and full throttle.

Maybe I'll try something like that next.

SMF spam blocked by CleanTalk