Please login or register.

Login with username, password and session length
Advanced search  

News:

Forum rules - please read before posting, it can save you a lot of time.

Author Topic: 'numpad' script?  (Read 2124 times)

0 Members and 1 Guest are viewing this topic.

geber

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 3
    • View Profile
'numpad' script?
« 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? :)
Logged

Igorrr

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 130
  • Ugh...Ughugh!!!!!!
    • View Profile
    • Struggle For Life And Honour
Re: 'numpad' script?
« Reply #1 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
   }
}
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5679
    • View Profile
    • Dead:Code Site
Re: 'numpad' script?
« Reply #2 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
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave
 

Page created in 0.296 seconds with 24 queries.