- Home /
Duplicate Question
Need help converting javascript to c# script
I got this javascript code i need to convert it to c# and i'm having some troubles. I've tried many things and it just won't convert and work. Here is the code
JavaScript Code:
#pragma strict
private var formNick = "";
private var formPassword = "";
var formText = "";
var URL = "http://gameserver.com/login.php"; //Not actual site
var hash = "hashcode";
private var textrect = Rect (10, 150, 500, 100);
function OnGUI() {
GUI.Label( Rect (10, 10, 80, 20), "Your Nick:" );
GUI.Label( Rect (10, 30, 80, 20), "Your Pass:" );
formNick = GUI.TextField ( Rect (90, 10, 100, 20), formNick );
formPassword = GUI.TextField ( Rect (90, 30, 100, 20), formPassword );
if ( GUI.Button ( Rect (110, 60, 100, 20) , "Register" ) )
{
Register();
}
if ( GUI.Button ( Rect (10, 60, 100, 20) , "Login" ) ){
Login();
}
GUI.TextArea( textrect, formText );
}
function Register() {
Application.LoadLevel("Menu_Register");
}
function Login() {
var form = new WWWForm();
form.AddField( "myform_hash", hash );
form.AddField( "myform_nick", formNick );
form.AddField( "myform_pass", formPassword );
var w = WWW(URL, form);
yield w;
if (w.error != null) {
print(w.error);
} else {
print("Test ok");
formText = w.data;
if (formText.Contains("Logged In Successful, Redirecting now..."))
{
Application.LoadLevel("Menu_Lobby");
// PhotonNetwork.playerName = formNick;
}
w.Dispose();
}
}
Answer by SaraCecilia · Jan 23, 2015 at 08:57 AM
For future reference, how to convert your script between Unityscript/Javascript and C#: http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html
Answer by zharik86 · Jan 23, 2015 at 07:28 AM
Ok, I converted for you, but you must learn, how converted script youself. Hope, this convertation is good start point to you.
private string formNick = "";
private string formPassword = "";
public string formText = "";
public string URL = "http://gameserver.com/login.php"; //Not actual site
public string hash = "hashcode";
private Rect textrect = new Rect (10, 150, 500, 100);
void OnGUI() {
GUI.Label(new Rect (10, 10, 80, 20), "Your Nick:");
GUI.Label(new Rect (10, 30, 80, 20), "Your Pass:");
formNick = GUI.TextField(new Rect (90, 10, 100, 20), formNick);
formPassword = GUI.TextField(new Rect (90, 30, 100, 20), formPassword);
if (GUI.Button(new Rect (110, 60, 100, 20), "Register")) {
Register();
}
if (GUI.Button(new Rect (10, 60, 100, 20), "Login")) {
StartCoroutine(this.Login()); //or use StartCoroutine("Login");
}
GUI.TextArea(textrect, formText);
}
public void Register() {
Application.LoadLevel("Menu_Register");
}
public IEnumerator Login() {
WWWForm form = new WWWForm();
form.AddField( "myform_hash", hash );
form.AddField( "myform_nick", formNick );
form.AddField( "myform_pass", formPassword );
WWW w = WWW(URL, form);
yield return w;
if (w.error != null) {
print(w.error);
} else {
print("Test ok");
formText = w.data;
if (formText.Contains("Logged In Successful, Redirecting now...")) {
Application.LoadLevel("Menu_Lobby");
//PhotonNetwork.playerName = formNick;
}
w.Dispose();
}
}
I hope that it will help you.
Assets/Players & Controls/Extra/Login_Controller.cs(40,25): error CS0119: Expression denotes a type', where a
variable', value' or
method group' was expected
ERROR
Follow this Question
Related Questions
Help converting C# to Javascript. 1 Answer
Can someone convert this into javascript? :) 1 Answer
How can I change this C# code into Javascript? 0 Answers
C# to UnityScript conversion help. 0 Answers
Convert to JavaScript 1 Answer