It’s actually probably more of a javascript question. Basically, I am trying to write a script to apply to a “Safe” object, which the player must open using a number combination.
So I set up a script with a keypad that comes up on the screen when the player hits the designated action button. It’s just a bunch of simple GUI.Buttons. I’m trying to figure out how I can store the numbers that the player punches in through the keypad into an array, and check to see if it is the right combination. I’ve got a basic psudo-code for it, but I’m not very good with javascript, so I was wondering if anyone has experience with this type of script, or if they have any tips?
Here is what I have now (or at least what is referring for to the keypad. it’s kind of a mixture between psudo-code and javascript right now… sorry.):
var intarray = int[4];
boolean right = false;
function buttonListener(int x)
{
if (button1 == pressed)
intarray[x] = 1;
else if (button2 == pressed)
intarray[x] = 2;
else if (button3 == pressed)
intarray[x] = 3;
else if (button4 == pressed)
intarray[x] = 4;
else if (button5 == pressed)
intarray[x] = 5;
else if (button6 == pressed)
intarray[x] = 6;
else if (button7 == pressed)
intarray[x] = 7;
else if (button8 == pressed)
intarray[x] = 8;
else if (button9 == pressed)
intarray[x] = 9;
else if (button0 == pressed)
/ntarray[x] = 0;
}
function OnGUI()
{
if (showGUI)
{
button1 = GUI.Button(new Rect(50,150,50,50), "1");
button2 = GUI.Button(new Rect(100, 150, 50, 50), "2");
button3 = GUI.Button(new Rect(150, 150, 50, 50), "3");
button4 = GUI.Button(new Rect(50, 200, 50, 50), "4");
button5 = GUI.Button(new Rect(100, 200, 50, 50), "5");
button6 = GUI.Button(new Rect(150, 200, 50, 50), "6");
button7 = GUI.Button(new Rect(50, 250, 50, 50), "7");
button8 = GUI.Button(new Rect(100, 250, 50, 50), "8");
button9 = GUI.Button(new Rect(150, 250, 50, 50), "9");
buttonDash = GUI.Button(new Rect(100, 300, 100, 50), "-");
button0 = GUI.Button(new Rect(50, 300, 50, 50), "0");
buttonEnter = GUI.Button(new Rect(50, 350, 150, 50), "Enter");
GUI.Box(new Rect(Screen.width/2-50, 150, 200, 50), "Enter Pin Number");
while(i < 4)
{
buttonListener(i)
i++;
}
if intArray== //code
win
else
lose
for(i=0, i<4, i++)
{
if(array_==code*)*_
* right = true;*
* else*
* break;*
* }*
}
All help is welcome
Thanks