Sign In Register

How can we help you today?

Start a new topic
Answered

Editing Cloud event code..

Maybe someone can assist, as I'm getting very confused here.

I have been trying to work with event creation in cloud, but when I write a script in cloud code for the event, then click save it saves fine... test harness runs the code... but I am unable to re-load the code for editing?

Every time I attempt it, it just starts the blank with 7 lines of comment code stating where to get the docs from portal (which btw just goes to here).


Thanks in advance.


Best Answer

Jason,


Mailed you separately regarding the example on calling Cloud Code from Unity.  I can't replicate what you are seeing here.  Can you go through the example I sent you and let me know if you are seeing the same thing happen. Either way can you confirm on this thread?  


Thx,


John.


For anyone interested in example of calling Cloud Code from Unity please see this document to set up and create both a new event and cloud code which gets triggered by the event:


https://docs.gamesparks.net/howtos/how-do-i-use-cloud-code-on-the-gamesparks-platform


Once you have the backend set up and working in the Test Harness.  Then the following code in Unity (i just created a button and executed this whenever the button was pressed):


void TestCloudCode () {

        

        Debug.Log("Calling TestCloudCode ... ");


        Dictionary<string, object> parameters = new Dictionary<string, object>();

        parameters.Add("pMessage", "test message from Unity");

        

        GameSparksSender sender = GameSparksApi.myAsyncLogEventRequest ("saveMessage", parameters);

        sender.sendAsync(TestCloudCodeCompletion);

    }


public void TestCloudCodeCompletion (IDictionary<string,object> result) {

        

        if (!result.ContainsKey("requestId")) {

            Debug.Log("TestCloudCodeCompletion: Error executing TestCloudCode - no connection");

        }

        else if (result.ContainsKey("error")) {

            Debug.Log("TestCloudCodeCompletion: Error executing TestCloudCode - check GS error");

        }

        else {

            Debug.Log(result);

        }

    }



Answer

Jason,


Mailed you separately regarding the example on calling Cloud Code from Unity.  I can't replicate what you are seeing here.  Can you go through the example I sent you and let me know if you are seeing the same thing happen. Either way can you confirm on this thread?  


Thx,


John.


For anyone interested in example of calling Cloud Code from Unity please see this document to set up and create both a new event and cloud code which gets triggered by the event:


https://docs.gamesparks.net/howtos/how-do-i-use-cloud-code-on-the-gamesparks-platform


Once you have the backend set up and working in the Test Harness.  Then the following code in Unity (i just created a button and executed this whenever the button was pressed):


void TestCloudCode () {

        

        Debug.Log("Calling TestCloudCode ... ");


        Dictionary<string, object> parameters = new Dictionary<string, object>();

        parameters.Add("pMessage", "test message from Unity");

        

        GameSparksSender sender = GameSparksApi.myAsyncLogEventRequest ("saveMessage", parameters);

        sender.sendAsync(TestCloudCodeCompletion);

    }


public void TestCloudCodeCompletion (IDictionary<string,object> result) {

        

        if (!result.ContainsKey("requestId")) {

            Debug.Log("TestCloudCodeCompletion: Error executing TestCloudCode - no connection");

        }

        else if (result.ContainsKey("error")) {

            Debug.Log("TestCloudCodeCompletion: Error executing TestCloudCode - check GS error");

        }

        else {

            Debug.Log(result);

        }

    }


thank you for the example.

This has helped a lot with getting it running now, but there is still one thing I am unsure how to pass through from unity to GS..

attribute 3, the json string, in the test harness, it is done similar to {"name":"testnick","Test":"99"} .

should this string be generated into a jsonobject first via simplejson, or should it be passed as a direct string?

If it is as a direct string, what is the best way to handle the quotations? Using it as is encapsulates the variables with each quote, and if I attempt to create a string enclosed in a single quote using string jsonstring='{"name":"testnick","Test":"99"}'; this results in an error in unity.

I can force the quotations into the string with string jsonstring="{\"name\":\"testnick\",\"Test\":\"99\"}"; but this also puts the backslash's into the return string which I'm not sure if that should be the case.


Can you please expand on that to clarify the ideal way to pass the json attribute in the event call?


Thanks.

or should I be creating a new dictionary for the json attribute in event?

Nevermind, found the answer with trial and error :)

For others with a simliar question, Create a second dictionary with the json fields,

Here is my adjusted code example:

 

 void testcloudcode()
 {
  Debug.Log ("Calling Test Code");
  Dictionary<string, object> parameters = new Dictionary<string, object>();
  Dictionary<string, object> attribute3 = new Dictionary<string, object>();
  attribute3.Add("Name","Testnick");
  attribute3.Add("Score","99");
  //string jsonstring='{"name":"testnick","Test":"99"}';
  parameters.Add("CC_Attr1","Test message from unity");
  parameters.Add("CC_Attr2","0");
  parameters.Add("CC_Attr3", attribute3);
  GameSparksSender sender=GameSparksApi.myAsyncLogEventRequest("CreateChar",parameters);
  sender.sendAsync(testcloudcodecompletion);
 }

 

 Thank you for your assistance John, and forgive my lack of JS knowledge.. I'm used to c# but it's the JS that I'm just learning to adjust to for the cloud.

Jason,


Glad you got that worked out. Let me know if you have any other issues.


John.

Thanks, one other question (a bit ahead of myself here) but what would be the ideal way to broadcast player locations to nearby players (Not world location, but game world).

I was thinking of using a routine to check the database for players locations and broadcast a change to those nearby when a player moves, but I'm wondering if this may put a heavier stress on the server than needed if there were a large number of online players?

Is this the best solution or is there something available in GS that I'm not yet familiar with that could be more suitable?

One way I was thinking, was using the player's geolocation as a world location seeing as its an already established variable in playerdata, if that can be modified consistently?

lol bugger can't delete posts.. I realized belatedly it wouldn't work like that anyway as I would need Z not just X and Y. :) so will need a json for worldlocation anyway.

but still curious as if the way of location updates I mentioned above would put too heavy a load on the server or not, or if the nosql is a non-persistant connection that would cause too many connections to become unstable.

Jason,


As you have realised, the location details on the player record are related to physical location in the real world.  From your description you are creating some kind of virtual world and would need an X, Y and Z to locate the player within the virtual world.  You could use the scriptData component of the player record to store this information - this field is there to allow you to extend the player record.  You can then use our messaging and notifications to "broadcast" player locations although there are potentially more options depending on your use case(s).


In terms of the impact on the server, provided the code you write to save and retrieve the locations is efficient, then this is exactly the kind of thing the platform is designed to do.


Cheers,


John.

Login to post a comment