Photon RaiseEvent and returning data from PlayFab CloudScript

Options
Hi,
I have a game linked to PlayFab that uses RaiseEvent with ForwardToWebhook true, and it correctly calls the Cloudscript.
My question is, how can we correctly return data from the CloudScript call?

I tried to follow your example here: https://community.playfab.com/questions/10944/playfab-photon-webhooks-return-value.html
which seemed to work initially but has since broken itself.

The steps I do:
1) C#
PhotonNetwork.RaiseEvent(23, jsonObject, true, new RaiseEventOptions() { ForwardToWebhook = true, Encrypt = true, Receivers = ReceiverGroup.Others });

2) CloudScript
handlers.RoomEventRaised = function(args)
{
    if (args.EvCode == 23)
    {
        if (playerWinningChallenge > 0)
        {
        	return { 'PlayerWinningChallenge' : playerWinningChallenge };
        }
    }
}
3) C#
   void OnEventCall(byte eventCode, object content, int senderId)
    {
            string searchString = "PlayerWinningChallenge=";
            int indexOf = contentString.IndexOf(searchString);
            if (indexOf >= 0)
            {
                // Parse the data
            }
    }
Am I missing something here? It now seems to be calling OnEventCall() for all my events now (i.e. for totally unrelated events that don't return anything), and never hitting the data parsing line.

I'm at a bit of a loss, since the CloudScript is a bit of an undebuggable blackbox, and returning data seems like an undocumented behaviour.

Thank you for your time,
Duncan

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited May 2018
    Options
    Hi @Dunk,

    Thank you for choosing Photon!

    First of all, you should know that there is no way to return Data from server to client using webhooks. At least not yet. Not many of you requested this and you need to make your voice heard.
    But there is an ugly workaround for the time being.
    It is a very ugly inconvenient way of doing this that may also break someday.
    So continue at your own risk.

    You can return a string in ErrorInfo events.
    You should enable those events first in webhooks settings using HasErrorInfo = true.
    Then return data from CloudScript (of type string) in the message using this format:
    "{ResultCode:<any integer different than zero>, Message:<stringified data>}"
    You will get the data in the error message of events of type ErrorInfo that you will have to parse twice (from message error format and from string to data), this is the ugliest part.


    For CloudScript I highly recommend switching to TypeScript asap and using an external logging service like loggly to log from CloudScript (especially in handlers calls not triggered using ExecuteCloudScript calls).