/// <summary> /// Gets the score and Debug.Logs it in the console as well as displays it in DisplayText. /// </summary> /// <returns>A Unity coroutine IEnumerator.</returns> public IEnumerator FetchScore() { // Create a variable to hold the recieved results from the server. string score = null; // Fetch data from the specified table and send the request with a specific parameter of EqualTo(), which will only return // values that are equal to "MoBackUser" under the column of "Name". table = new MoBackTableInterface("TestMoback"); MoBackRequest <List <MoBackRow> > tableContentsFetch = table.GetRows(new MoBackRequestParameters().EqualTo("Name", "MoBackUser")); yield return(tableContentsFetch.Run()); // If the fetch request is successful, display the data. if (tableContentsFetch.State == MoBackRequest.RequestState.COMPLETED) { List <MoBackRow> rows = tableContentsFetch.ResponseValue; for (int i = 0; i < rows.Count; i++) { if (rows[i].GetString("Name") == "MoBackUser") { // Display the score in the debug console and in the DisplayText text object in the scene. score = rows[i].GetInt("Score").ToString(); Debug.Log("Score: " + score); menuHandler.Display("Score: " + score.ToString()); } } } else { Debug.Log(tableContentsFetch.errorDetails); } }
public IEnumerator Data() //здесь происходит поиск данных по ID и при + результате внесение их в переменные для дальнейшей работы { exampleTable = new MoBackTableInterface("PlayersData"); MoBackRequest <List <MoBackRow> > tableContentsFetch = exampleTable.GetRows(); yield return(tableContentsFetch.Run()); if (tableContentsFetch.State == MoBackRequest.RequestState.COMPLETED) { rows = tableContentsFetch.ResponseValue; for (int i = 0; i < rows.Count; i++) { if (rows [i].GetString("IDcode") == currentID) { rowPosition = i; MoBackRequest response1 = exampleTable.DeleteObject(rows [rowPosition].GetString("objectId")); yield return(response1.Run()); a = rows [i].GetFloat("aValue"); b = rows [i].GetFloat("bValue"); x = rows [i].GetFloat("xValue"); y = rows [i].GetFloat("yValue"); maxScene = rows [i].GetInt("maxScene"); break; } } } else { Debug.Log(tableContentsFetch.errorDetails); } initialized = true; }
/// <summary> /// Updates an existing row with a new score and notifies the user when successful. /// </summary> /// <returns>A Unity coroutine IEnumerator.</returns> /// <param name="score">Score to submit.</param> public IEnumerator SubmitScore(int score) { // Create a new table called "TestMoBack" if it hasn't already been created; otherwise, specify which table you want to work with. table = new MoBackTableInterface("TestMoback"); // Send a request for data to the server with a specific set of parameters. MoBackRequest <List <MoBackRow> > tableContentsFetch = table.GetRows(new MoBackRequestParameters().EqualTo("Name", "MoBackUser")); yield return(tableContentsFetch.Run()); // Once the request has been completed, manipulate the fetched data. if (tableContentsFetch.State == MoBackRequest.RequestState.COMPLETED) { List <MoBackRow> rows = tableContentsFetch.ResponseValue; // Update the last item in the table to a new score and send to the server. MoBackRow newRow = rows[rows.Count - 1]; newRow.SetValue("Score", score); MoBackRequest response = newRow.Save(); // Wait for a response before displaying that the request was successful. yield return(response.Run()); if (response.State == MoBackRequest.RequestState.COMPLETED) { menuHandler.Display("Score submitted successfully."); } else { menuHandler.Display("Request was not successful. Please double check your app ID and/or environment key."); // Display an error should one occur. Debug.Log(response.errorDetails); } } else { // Display an error should one occur. Debug.Log(tableContentsFetch.errorDetails); } }