Quantcast
Viewing all articles
Browse latest Browse all 36

how can i fix this error CS7036? its an issue comunicating a callback from a server

Hello guys, I’m doing a stock list that fill itself with the data of the tables in a server (like an inventory system for a mmorpg). for that, I’m using a Web.cs that call the info from a php file and a Stock.cs that is using the info obtained to create an item Stock for each StockID and fill the name with the Name of the item. the error that I’m obtaining is: Error CS7036 There is no argument given that corresponds to the required formal parameter 'callback' of 'Web.GetStockID(string, Action)' at my Web.cs i think that is because Stock.cs. I've been checking and i cant spot why, please help me. thanks. PD: im leaving the scrips below (first web, and then stock): WEB> // Start is called before the first frame update void Start() { StartCoroutine(GetDate()); StartCoroutine(GetUsers()); } public void ShowStock() { StartCoroutine(GetStockID(Main.Instance.UserInfo.UserId)); } IEnumerator GetDate() //ordena los mensajes en forma de lista { using (UnityWebRequest webRequest = UnityWebRequest.Get("http://localhost/ar_demo/GetDate.php")) { // Request and wait for the desired page. yield return webRequest.SendWebRequest(); if (webRequest.isNetworkError) { Debug.Log(webRequest.error); } else { //Show Results as Text Debug.Log(webRequest.downloadHandler.text); //Or retrieve results as binary byte[] results = webRequest.downloadHandler.data; } } } IEnumerator GetUsers() //ordena los mensajes en forma de lista { using (UnityWebRequest webRequest = UnityWebRequest.Get("http://localhost/ar_demo/GetUser.php")) { // Request and wait for the desired page. yield return webRequest.SendWebRequest(); if (webRequest.isNetworkError) { Debug.Log(webRequest.error); } else { //Show Results as Text Debug.Log(webRequest.downloadHandler.text); //Or retrieve results as binary byte[] results = webRequest.downloadHandler.data; } } } public IEnumerator Login(string Username, string Password) //ordena los mensajes en forma de lista { WWWForm form = new WWWForm(); form.AddField("loginUser", Username); form.AddField("loginPass", Password); using (UnityWebRequest webRequest = UnityWebRequest.Post("http://localhost/ar_demo/Login.php", form)) { // Request and wait for the desired page. yield return webRequest.SendWebRequest(); if (webRequest.isNetworkError || webRequest.isHttpError) { Debug.Log(webRequest.error); } else { Debug.Log(webRequest.downloadHandler.text); Main.Instance.UserInfo.SetCredentials(Username, Password); Main.Instance.UserInfo.SetID(webRequest.downloadHandler.text); if (webRequest.downloadHandler.text.Contains("wrong credentials") || webRequest.downloadHandler.text.Contains("Username does not exist.")) { Debug.Log("Try again."); } //if we loging correctly else { Main.Instance.ImmersiveMediahype.SetActive(true); Main.Instance.Login.gameObject.SetActive(false); } } } } public IEnumerator GetStockID(string UserID, Action callback) //ordena los mensajes en forma de lista { WWWForm form = new WWWForm(); form.AddField("UserID", UserID); using (UnityWebRequest webRequest = UnityWebRequest.Post("http://localhost/ar_demo/GetStockID.php", form)) { // Request and wait for the desired page. yield return webRequest.SendWebRequest(); if (webRequest.isNetworkError) { Debug.Log(webRequest.error); } else { //Show Results as Text Debug.Log(webRequest.downloadHandler.text); string jsonArray = webRequest.downloadHandler.text; //Call callback function to pass results callback(jsonArray); } } } public IEnumerator GetStock(string StockID, System.Action callback) //, System.Action callback) //ordena los mensajes en forma de lista { WWWForm form = new WWWForm(); form.AddField("StockID", StockID); using (UnityWebRequest webRequest = UnityWebRequest.Post("http://localhost/ar_demo/GetStock.php", form)) { // Request and wait for the desired page. yield return webRequest.SendWebRequest(); if (webRequest.isNetworkError) { Debug.Log(webRequest.error); } else { //Show Results as Text Debug.Log(webRequest.downloadHandler.text); string jsonArray = webRequest.downloadHandler.text; //Call callback function to pass results callback(jsonArray); } } } Stock> Action _createItemsCallback; // Start is called before the first frame update void Start() { _createItemsCallback = (jsonArrayString) => { StartCoroutine(CreateItemsCoroutine(jsonArrayString)); }; CreateItems(); } public void CreateItems(){ string UserID = Main.Instance.UserInfo.UserId; StartCoroutine(Main.Instance.Web.GetStockID(UserID,_createItemsCallback)); } IEnumerator CreateItemsCoroutine(string jsonArrayString) { //parsing the jsonArrary as an array JSONArray jsonArray = JSON.Parse(jsonArrayString) as JSONArray; for (int i = 0; i < jsonArray.Count; i++) { //create local variables bool isDone = false; //is it done? string DiscountItem = jsonArray[i].AsObject["StockID"]; JSONObject itemNamejson = new JSONObject(); //create a callback to get the information from web.cs Action getDiscountCallback = (ItemName) => { isDone = true; JSONArray tempArray = JSON.Parse(ItemName) as JSONArray; itemNamejson = tempArray[0].AsObject; }; StartCoroutine(Main.Instance.Web.GetStock(DiscountItem, getDiscountCallback)); //Wait until the callback is called from WEB (inf finish dowloading) yield return new WaitUntil(() => isDone == true); //instantiate ameObject (Item Prefab) GameObject stock = Instantiate(Resources.Load("PREFABS/stock") as GameObject); stock.transform.SetParent(this.transform); stock.transform.localScale = Vector3.one; stock.transform.localPosition = Vector3.zero; // fill the information stock.transform.Find("Name").GetComponent().text = itemNamejson["Name"]; //continue to the next item } }

Viewing all articles
Browse latest Browse all 36

Trending Articles