Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: geber on November 08, 2005, 05:20:33 PM

Title: 'numpad' script?
Post by: geber on November 08, 2005, 05:20:33 PM
Hello.

Maybe anyone can help me realize this script:

For entering in the next room, a hero must enter some numberic sequence, ex. 12345
Numpad do not have a screen, so if player press wrong key, all previous typed nums reseting.

What a best way to do this? :)
Title: Re: 'numpad' script?
Post by: Igorrr on November 08, 2005, 07:07:06 PM
My first thoughts are in case you will use the keypad for various functions or different scenes you will have global listeners for these key-pressed events. In this case I'd include in the scene a script listening to key-pressed events and save the code status in a variable.

Hard to put in words. Well imagine you have a variable called level and a code "1 2 3 4 5" stored in an Array keycode[].
now we start off in the scene with level = 1.

if key "1" is pressed it will check the current level (1) and check keycode[level]. In this case keycode[1]=1 so the script would advance to level = 2. When the next numkey event is sent to the script it will check again. For example numkey 3 is pressed it will see keycode[2]=2  -->NOT 3 so the script will reset level back to 1 and all starts over again.

is that understandable? ???

Let's try pseudo-code

variables:

keycode[1]=1; -->five digit code 1 - 5
keycode[2]=2;
keycode[3]=3;
keycode[4]=4;
keycode[5]=5;

level = 0; -->the level of code entered (it's successful number advances in level, wrong number resets to one)

numkey; -->the key that has been pressed.

Event: when a numkey has been pressed
{
 if (numkey == keycode[level])
   {
     level++; correct number entered so level advances one more step
     if (level > 5) trigger event / unlock door;  if level has advanced over 5 it means the code has been entered successfull and can trigger the event (e.g. to unlock a door)
   }
 else
   {
     level=1; if a wrong number is entered level is reset to 1 and you need to type all over again
   }
}
Title: Re: 'numpad' script?
Post by: Mnemonic on November 08, 2005, 10:04:40 PM
There's also some, slightly confusing :), keypad discussion in this thread: http://forum.dead-code.org/index.php?topic=1071.msg7759#msg7759