- Home /
WWWForm in C#
Need to convert this into Javascript:
var url = "http://www.slimebass.com/test.php";
function Start() {
var form = new WWWForm();
form.AddField( "xp", Random.Range(0, 20));
var download = new WWW( url, form );
yield download;
if(download.error) {
print( "Error downloading: " + download.error );
return;
} else {
Debug.Log(download.text);
}
}
//SLIMEBASS
Comment
This is an easy conversion, and the ability to convert is a good (almost necessary if you follow UA) skill to have. Here is a link to the the differences between the two languages:
http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html
I highly recommend that you take a shot at doing the conversion yourself and post a new question if you get stuck.
Thanks for the link. Still got 2 more error (7,22)(9,22) using UnityEngine; using System.Collections;
public class Form : $$anonymous$$onoBehaviour {
public int url = "http://www.slimebass.com/test.php";
void Start (){
public int form = new WWWForm();
form.AddField( "xp", Random.Range(0, 20));
public int download = new WWW( url, form );
yield return download;
if(download.error) {
print( "Error downloading: " + download.error );
return;
} else {
Debug.Log(download.text);
}
}
}
Best Answer
Answer by robertbu · May 09, 2013 at 06:24 PM
A few extra gotchas there I did not see on first read. Here is a untested conversion:
using UnityEngine;
using System.Collections;
public class Form : MonoBehaviour {
public string url = "http://www.slimebass.com/test.php";
IEnumerator Start (){
WWWForm form = new WWWForm();
form.AddField( "xp", Random.Range(0, 20));
WWW download = new WWW( url, form );
yield return download;
if((!string.IsNullOrEmpty(download.error))) {
print( "Error downloading: " + download.error );
} else {
Debug.Log(download.text);
}
}
}