Sign In Register

How can we help you today?

Start a new topic
Answered

Upload/Download multiple data using unity

how can i modify this to upload multiple strings and be able to differentiate them upon download


 for upload i have this

 

var form = new WWWForm();
        form.AddField("somefield", "somedata");
        form.AddField("somefield", "somedata");
        form.AddField("somefield", "somedata");
        
  
        WWW w = new WWW(uploadUrl, form);
        yield return w;

 




 for download i seem to be stuck on how to request one or differentiate the three


 


 

var downloadform = new WWWForm();
        form.AddField("somefield", "somestring");
        form.AddField("somefield", "somestring");
        form.AddField("somefield", "somestring");
        
  
        WWW w = new WWW(downloadUrl, downloadform);
        yield return w;
         
        w.text

 


Best Answer

Hey There,


Gamesparks doesn't use WWWForms for posting and getting data from our servers, we use websockets instead.
However, you can still defiantly upload and download multiple strings, and you can preform whatever calculations you want, or add that info to a database.

 

One way to do this is to create an event in the Gamesparks portal for your game and add multiple strings as your event attributes...
[ You can check out a tutorial on that here -> https://docs.gamesparks.net/developer-portal/events]


Then, to upload those strings in your C# code,  you can call the LogEventRequest() like so...

 

new GameSparks.Api.Requests.LogEventRequest()
			.SetEventKey("YOUREVENT")
				.SetEventAttribute("STRING1", "abc")
					.SetEventAttribute("STRING2", "def")
						.SetEventAttribute("STRING3", "ghi")
							.Send((response) => {


						});

 

Then, in your cloud-code, the server can get these strings and you can manipulate them as you want.
[ Check out this tutorial for how to use cloud-code -> https://docs.gamesparks.net/howtos/how-do-i-use-cloud-code-on-the-gamesparks-platform ]


In order to get some data back you can use the Spark.setScriptData() function in your cloud code, and you could set that to be a list of strings, or an array for example, or if you would like the strings to be sent as separate data, you can use Spark.setScriptData() several times, using a different key...


 

Spark.setScriptData("string1", firstData);
Spark.setScriptData("string2", secondData);
Spark.setScriptData("string3", thirdData);

 

Then you can call the LogEventRequest() for this event which will return your strings you can select each data-set by its key....


 

new GameSparks.Api.Requests.LogEventRequest()
			.SetEventKey("YOUREVENT")
				.Send((response) => {
				
					if(!response.HasErrors) // check we dont have errors
					{
						string data1 = response.ScriptData.GetString("string1");
						string data2 = response.ScriptData.GetString("string2");
						string data3 = response.ScriptData.GetString("string3");
					}
				});

 

 

And then you can use the strings as you please...
Hope that answers your question.

-Sean

1 Comment

Answer

Hey There,


Gamesparks doesn't use WWWForms for posting and getting data from our servers, we use websockets instead.
However, you can still defiantly upload and download multiple strings, and you can preform whatever calculations you want, or add that info to a database.

 

One way to do this is to create an event in the Gamesparks portal for your game and add multiple strings as your event attributes...
[ You can check out a tutorial on that here -> https://docs.gamesparks.net/developer-portal/events]


Then, to upload those strings in your C# code,  you can call the LogEventRequest() like so...

 

new GameSparks.Api.Requests.LogEventRequest()
			.SetEventKey("YOUREVENT")
				.SetEventAttribute("STRING1", "abc")
					.SetEventAttribute("STRING2", "def")
						.SetEventAttribute("STRING3", "ghi")
							.Send((response) => {


						});

 

Then, in your cloud-code, the server can get these strings and you can manipulate them as you want.
[ Check out this tutorial for how to use cloud-code -> https://docs.gamesparks.net/howtos/how-do-i-use-cloud-code-on-the-gamesparks-platform ]


In order to get some data back you can use the Spark.setScriptData() function in your cloud code, and you could set that to be a list of strings, or an array for example, or if you would like the strings to be sent as separate data, you can use Spark.setScriptData() several times, using a different key...


 

Spark.setScriptData("string1", firstData);
Spark.setScriptData("string2", secondData);
Spark.setScriptData("string3", thirdData);

 

Then you can call the LogEventRequest() for this event which will return your strings you can select each data-set by its key....


 

new GameSparks.Api.Requests.LogEventRequest()
			.SetEventKey("YOUREVENT")
				.Send((response) => {
				
					if(!response.HasErrors) // check we dont have errors
					{
						string data1 = response.ScriptData.GetString("string1");
						string data2 = response.ScriptData.GetString("string2");
						string data3 = response.ScriptData.GetString("string3");
					}
				});

 

 

And then you can use the strings as you please...
Hope that answers your question.

-Sean