Key codes

Started by shaungaryevans, Fri 22/05/2009 22:50:32

Previous topic - Next topic

shaungaryevans

Hi,

I have made numbered pad and now i'm linking the my number keys on my keyboard. How the numbered pad works, is you have got a 6 digit number like 253645 and if you press a wrong number you get game over. I can do it if the code has all 6 digits different. Bit i'm having a bit of trouble with codes that has a same number twice such as 253645 and I'm tring to link the 5 key up to them. I have got to different codes for them.

if(keycode =='5'){
if(vcomputer_3 == 1){bad3_2.Visible = false; vcomputer_3 = 2;} else {digipad_2.Visible = false; cEgo.ChangeRoom(12, 701, 519);}
if(vcomputer_3 == 5) {bad3_6.Visible = false; vcomputer_3 = 6;} else {digipad_2.Visible = false; cEgo.ChangeRoom(12, 701, 519);}}

but this don't work because if i press 5 the first time. it will read the second line of coding which is false. Is there any way I can to the two codes at different times using the same key on the same GUI please

Anteater

If I understand correctly, I think you could use an array to store the numbers contained within the code. Then, just compare the code that was typed by the user with the correct code.

shaungaryevans

This won't work because when the user presses the first right number a light will come on. when the user pesses the second number the second light will come on. They are not typing it into a text box

Gilbert

Some quick idea (not tested):
Code: ags

int passcount=0;
int passkeys[6];

... (initialise the array passkeys[] with the keycodes, blah bla bla)

if (keycode==passkeys[passcount]){ //One more key correct
  passcount++;
  if (passcount==6) { //All keys correct
     //Do whatever you want when the whole correct code is entered
  }
} else { //Wrong key entered
  //Game over
}

shaungaryevans

Can I deactivate a key then activate it later on in the game?

SMF spam blocked by CleanTalk