Log in script

I only know that this requires a an array. I have only seen arrays used once, in an inventory script. This is my next big chalange. Can any of you get me started?

why would a login script need an array ? where do you login ?

If you want your login system to allow people to log in to the same account from different computers over the Internet, you will probably need to have a web server with a MySQL database, and connect to it through Unity using WWWform. There are a number forum threads covering this topic with examples, just use the search.

Here is a decent one: http://forum.unity3d.com/threads/24721-Tutorial-Unity-and-PHP-login-script-simple-but-useful

Hm… What I thought is that you could make it in js in unity. That way when a user trys to log in, unity checks an array of user names and matching passwords. right of of a web player.

But, if I do need to do it in php I have blue voda to help with that.

well you can make it in unity, it’s not secure but you can.
create a hashtable, add the usernames passwords to the hashtable.
then when a user clicks the login button, loop through the hashtable and match the key to the input username and validate the password with the hashtable value.

Webplayers cannot write to the local file system, for security reasons (except for playerprefs).

Even if it could, if someone registered an account on one computer and it was saved to a file on that computer, they would only ever be able to log in on that computer. Eventually, if you wanted your system to work on other computers (otherwise, why would you want a login system?), you will have to do something web-related.

Ok so unity is out, but how would the php method even put you into the game? I load your profile? What I need is a login you can get type in, that will give you your settings. One example is the one RuneScape has (www.runescape.com - then go to play online).

If you click the link I posted in the above post, you can see exactly how. You need a webserver with mysql and php, and you would create a mysql table for your users, with usernames and passwords, and a php script that would pull the usernames and passwords and be able to receive post requests to check if usernames and passwords posted to it are valid. Then in Unity, you would create a scene with gui fields for username and password, and write a script that connects to the php script on your webserver, and posts the username and password from the unity user to the php script, the php script checks if its a valid username/password pair in the database, and sends back to unity whether or not it was a valid pair. If it is a valid pair, you would allow the users to load the next scene.

this is what i’m using to request data from the server using http

static var server : String = "http://localhost:8080/hideandseek";
static var userName: String = "";
static var status :String  = "";

var userNameTemp: String = "";

function Start(){
	// make sure the app runs in background.
	Application.runInBackground = true;	
}

function OnGUI () {

   userNameTemp = GUI.TextArea(Rect(10,50,200,25),userNameTemp);

   if(GUI.Button(Rect(10,10,100,30),"Login")){
        login();
   }

   GUI.Label(Rect(120,20,400,20),status);

}

function login(){
	userName = userNameTemp.ToUpper();
	var url = server + "/login?name=" + userName;
	Debug.Log(url);
    var localWWW = new WWW(url);
    yield localWWW;
    status = localWWW.text;
    localWWW = null;
}

or us can use the request using POST like this sample where Im sending some user position data, and splitting the response by “;”

		var form = new WWWForm();
		form.AddField("name", MainScript.userName);
		form.AddField("x", transform.position.x.ToString() );
		form.AddField("y", transform.position.y.ToString() );
		form.AddField("z", transform.position.z.ToString() );

		// make the remote call	
		var url = MainScript.server + "/sync";
	    localWWW = new WWW(url, form);
	    yield localWWW;
		
		form = null;	
		activeUsers = new Array();
	    
	    // parse the result.
	    var users = localWWW.text.Split(";"[0]);
...

Legend411, I read the tutorial, I asked some question so I will wait. One problem is that I am probably laking mysql. I think I have only heard mysql once before, and don’t even know what it is.

Zu… MySQL is the most common database management system used on the web… Google it to read up on it. This forum itself is a web application powered by MySQL (and php, I think).

WHat I gt is that it is a DB manager that lots of users can connect to, I am going to download a version. Sorry for such a lack of knowlage.

Ok… This happens :
ERROR 1045 (28000): Access denied for user ‘ODBC’@‘localhost’ (using password: NO)
I ran the mysql connecter ODBC installer too.
Also, when I try to follow tutorial 3.1 from the mysql website (http://dev.mysql.com/doc/refman/5.5/en/connecting-disconnecting.html). All I get is Acess Denied