x


why doesn't this script work

Im trying to make a password system that loads a level

var passwordToEdit : String = "My Password";

    var LevelTovLoad : String;



private var OneTowTreeFour : String;



    function OnGUI () 

    {

        passwordToEdit = GUI.PasswordField (Rect (10, 10, 200, 20), passwordToEdit, "*"[0], 25);



        if(passwordToEdit == OneTowTreeFour)

        {

            Application.LoadLevel(LevelTovLoad);

        }

    }

please help me iv really wanted to no this for a while now

more ▼

asked Apr 05 '11 at 03:29 PM

josifjoey gravatar image

josifjoey
5 6 8 11

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

I think that you need to change you script to:

    var passwordToEdit : String = "My Password";    
    var correctPassword : String = "OneTowTreeFour";
    var levelToLoad : int = 0;

    function OnGUI () {
        passwordToEdit = GUI.PasswordField (Rect (10, 10, 200, 20), passwordToEdit, "*"[0], 25);

        if(passwordToEdit == correctPassword) {    
            Application.LoadLevel(levelToLoad);    
        }    
    }

Besides rearranging your code, I changed your "LevelTovLoad" to "levelToLoad" and made it an intager instead of a string, so that you only have to put in one number. I changed the Private Variable "OneTowTreeFour" to a Public Variable called "correctPassword" and made OneTowTreeFour into the answer...

Oh, one more thing, if you want some of those really good "coder-people" to answer (or even read) your question, you should use descriptive questions, and try your best to explain your problem... Anyway, I hope I helped!

more ▼

answered Apr 05 '11 at 03:40 PM

AVividLight gravatar image

AVividLight
1.9k 68 100 129

(comments are locked)
10|3000 characters needed characters left
        var desiredUsername = "user";
        var stringToEdit = "";
        var desiredPassword = "admin";
        var passwordToEdit = "";

      function OnGUI () {
   // Make a multiline text area that modifies stringToEdit.
      GUI.Label(Rect (10, 10, 60, 20), "Username: ");
      GUI.Label(Rect (10, 35, 60, 20), "Password: ");

     stringToEdit = GUI.TextField (Rect (75, 10, 200, 20), stringToEdit, 200);

     passwordToEdit = GUI.PasswordField (Rect (75, 35, 200, 20), passwordToEdit, "*"[0], 25);

    if(stringToEdit == desiredUsername)
          {
    if(passwordToEdit == desiredPassword)
          {
        Application.LoadLevel(LevelTovLoad);
          }
          }
          }
more ▼

answered Apr 05 '11 at 03:34 PM

robertmathew gravatar image

robertmathew
571 35 41 51

here the user name is user and password is admin when u enter the correct password and user name defined var as desiredUsername and desiredPassword you will go to levelToLoad

Apr 05 '11 at 03:38 PM robertmathew

thanks :) big time

Apr 05 '11 at 03:43 PM josifjoey
(comments are locked)
10|3000 characters needed characters left
       private var correctLogin : boolean;

       function Update()
              {
       correctLogin = (username == "user" && password == "admin");
              }


        function OnGUI()
           {
      var windowRect : Rect;
      windowRect.x = Screen.width / 2 - 100;
      windowRect.y = Screen.height / 2 - 50;
      windowRect.width = 200;
      windowRect.height = 100;

    GUI.Window(0, windowRect, OnWindowGUI, "Authentication");
          }

   function OnWindowGUI()
          {
     username = GUILayout.TextField(username);
     password = GUILayout.PasswordField(password, '*'[0]);
     GUI.color = btnColor;
   if (GUILayout.Button("Login") && correctLogin)
          {
       Application.LoadLevel(LevelTovLoad);

          }

          }
more ▼

answered Apr 05 '11 at 03:45 PM

robertmathew gravatar image

robertmathew
571 35 41 51

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3570
x430
x23

asked: Apr 05 '11 at 03:29 PM

Seen: 654 times

Last Updated: Apr 05 '11 at 03:52 PM