#How to properly put args in CloudCode calls from Unity Client?

1 messages · Page 1 of 1 (latest)

versed cape
#

Hi. I have been trying this for days now and never manage to properly get my Args transmitted into CloudCode:

I want only a minimum viable test, so that I have something to start with.

Let's say I have a .cs with "TestCloudCode".

`public async void TestCloudCode()
{
var parameters = new Dictionary<string, object>
{
{ "targetPlayerId", "Player123" },
{ "sectorKey", "Sector01" },
{ "damageAmount", 10 }
};

    try
    {
        var result = await CloudCodeService.Instance.CallEndpointAsync<Dictionary<string, object>>(
            "Test", // endpoint name
            parameters // this dictionary must be serializable
        );

        Debug.Log("Cloud Code executed successfully: " + result["success"]);
        Debug.Log("Returned args: " + (result.ContainsKey("received") ? result["received"] : "none"));
    }
    catch (System.Exception e)
    {
        Debug.LogError("Cloud Code error: " + e);
    }
}`

Where is this wrong? Endpoint is 100% correct name, I get the Executed Successfully message, but my Cloud Code doesn't write any logs, and I am getting insanely desperate..

My Test CloudCode Script is:

`module.exports = async (args, context) => {
// This will log all incoming arguments
console.log("Received args: " + JSON.stringify(args));

return {
    success: true,
    receivedArgs: args
};

};`

I would be so so happy if someone told me what I have to do. The idea is to write to trigger as Player A writing into Player B public key Cloud Save Data after calling the "Test" function, that would be the next step.

If there's any example I'll be very helpful, AI officially lost my trust in this regard 😄

#

TLDR:

step 1: make successful cloud code calls whilst sending some args into it.

Step 2: call CloudCode Method “DealDamage” with args ownerid of a target player,together with one int (damage) and one string (zoneName), and make a cloudsave call to that target players public key out of that (remove HP of the damage value of zone ZoneName).

I have no idea when I have to wrap something in JSON and when I can keep sending it vanilla…

grizzled crag
versed cape
#

As someone who has used some UGS, net code and several years of general unity stuff, I don’t understand anything that wants to tell me, is there any good tutorial how to set this up? It’s all very generic and I have very hard time following or understanding lots of the words.

#

I just want to be able to give player A the option to write into player Bs public key, I don’t care how just don’t want 500 different things to get there

grizzled crag
#

Also if for this interaction Player A and Player B are always both going to be online when the interaction occurs, you could try using Push Messages

versed cape
#

I honestly hope there will be some simpler way introduced at some point. Found similar questions a lot on the web and making other player data or global game/custom data also writable for clients (I understand the downside and risks of opening them up and not make it server calls) feels so restrictive

#

But thanks you two!

obsidian ibex
#

Yea you really really do not want to open up players being able to manipulate other player data