Sign In Register

How can we help you today?

Start a new topic
Answered

Data associated to Real-Time session / GameSparks match

Good morning,


Ours is a multiplayer 1v1 (for now) Turn Based Strategy game.


We are using Unreal Engine 4 for this project and we initially thought about using UE4's online system using GameSparks merely as a DB Backend Service, not to control the game logic itself. But we recently changed that idea, since the game doesn't have a heavy load talking about the number of messages sent between player and server (move that unit there, attack here and so on; nothing real-time like).


We want the game to be server-authoritative and, thus, there are some calculations that must be done in the server-side. E.g.: When I select this unit, to which tiles can I move?

So, we won't use GameSparks as a way to send data between player, the data must be treated in server and then sent back to player/s.


To do that calculations, we need to have some data attached to the 'match' itself such as the board and score, etc. There is the possibility to store the data in NoSQL or in SparkCache and retrieve it from there any time in which an event arrives to the server but we don't really see this as the correct approach, is it? Is there any way to have some information in 'memory' associated to the session?


Sorry if we are missing something. We did a deep research and couldn't find anything.


Best regards and thank you as always,

Anas Belli dev team


Best Answer

Hey guys.


Have you had a look at the Realtime scripts? It is in the Cloud code section of the backend. You can use the realtime scripts to do any server authoritative logic and persist data for players while the session remains active. You can make requests on behalf of players here too. 


I've added you to the game RTTest which has a simple authority script you can have a look at. The script will be found under Cloud Code -> Realtime scripts -> RTScriptAuthority 

I will make a tutorial for it soon. 

Hope this helps you for now,

Omar


Answer

Hey guys.


Have you had a look at the Realtime scripts? It is in the Cloud code section of the backend. You can use the realtime scripts to do any server authoritative logic and persist data for players while the session remains active. You can make requests on behalf of players here too. 


I've added you to the game RTTest which has a simple authority script you can have a look at. The script will be found under Cloud Code -> Realtime scripts -> RTScriptAuthority 

I will make a tutorial for it soon. 

Hope this helps you for now,

Omar

Hello Omar,


You are awesome, thanks for your fast help!


Wow, I'm really astonished on how this script of yours works... Is really the variable playerData shared between all the times the script is run? That would be great and it quite opens a new world in front of us.


Thank you and very best,

Anas Belli dev team


PS. Your support, guys, is actually the best I've received so far. Fast and great.


Glad you're happy with the support guys!


playerData is only persistent for the session, but it can be loaded from any collection on the backend. For example:


When the session starts, you can access the player's collection and retrieve the data you need and populate playerData with it.


  

  var accountInfoReq = new RTSession.newRequest().createAccountDetailsRequest();
    
    accountInfoReq.send(function(response){
        var exampleData = response.scriptData.exampleString;
        playerData[player.getPeerId()] = {"exampleVar":exampleData};
    })

  

You can also call logEvent requests which return exactly what you need, and that can access any collection or piece of data in the backend.


The RTSession has the ability to call requests and pull data but doesn't have any reference to the backend, so unfortunately Spark.function will not work. However using requests you can access anything you want externally.


Any player sharing the session can access playerData too using a packet that returns it.


Hope this helps,

Omar



Yeah, I meant shared between all executions in the frame of the session! 


This is awesome and really powerful, Omar, thank you very much.


Thanks again,

Anas Belli dev team

Glad to help!


Here if you need any more help,

Omar

Dear Omar,


I'm have some troubles using LogEvenRequest from RTSession.


I want the RTScript to know some data associated to each participant of the match and so, in the MatchmakingRequest I have added a JSON to the participantData of the match.


From the script i'm trying to retrieve that information. I first tried to do so by making a matchDetailsRequest this way (in the onPlayerConnect event):

RTSession.newRequest().createMatchDetailsRequest()
            .setPlayerId(player.getPlayerId())
            .setMatchId(matchId)
            .setRealtimeEnabled(true)
            .send(function(response){
                logger.debug(response);
            });

 Unfortunately, this is not working because the response received does not contain the participant Data, so I tried to get that info in a custom event that I'm trying to call via LogEventRequest, I have done as said in this tutorial:


https://docs.gamesparks.com/tutorials/real-time-services/creating-and-using-real-time-scripts.html#set-timeout


And my piece of code inside the RealTime scripts is:

RTSession.newRequest().createLogEventRequest()
            .setEventKey("matchData")
            .setPlayerId(player.getPlayerId())
            .setScriptData({"matchId": "1234"})
            .send(function(response){
                logger.debug(response);
            })

First: I added the playerId stuff because I was receiving Not Authorized.

Second: Now I'm receiving scriptData: "UNKNOWN"


The LogEventRequest is working as intended using TestHarness and its configuration is as follows:

aSyQd-4Sovs0ewxwya45jLLUEaCRxrk_gA.png


Any idea? 


Thanks and best,

AB dev team

Hey, Omar,


Sorry for double posting!!


How's the best way to test the real-time scripting? Is there anyway to do it via Test Harness? I couldn't find a way and use megalithic Unreal4 game to do it is quite uncomfortable. I also saw that there's no support for RT in JavaScript sdk, is that still true?


Thanks and best,

Ignacio

Hi Ignacio,


1st thing is first, The logevent request


The attribute is not scriptData, that's why your request is probably being denied. instead of 


.setScriptData({"matchId": "1234"})


try


.matchID("1234")


No unfortunately there's no RT capabilities in the JavaScript SDK. However I can help you create debug build if you want on Unreal 4.


Hope this helps,

Omar 


Hello Omar,


Thanks for answering us in Sunday!


Unfortunately, this is not working. This is another LogEventRequest with the event attribute being boardId instead of matchId, but it's the same case, so I've tried the following:

var req = RTSession.newRequest()
        .createLogEventRequest()
        .setEventKey("getBoard");
    req.boardId("1");
    req.setPlayerId(players[1].id)
        .send(function(response){
            RTSession.getLogger().debug(response);
        });

 

Error: null is not a function


 

var req = RTSession.newRequest()
        .createLogEventRequest()
        .setEventKey("getBoard");
    req.boardId = "1";
    req.setPlayerId(players[1].id)
        .send(function(response){
            RTSession.getLogger().debug(response);
        });

 

Not error here, but the LogEventRequest is not receiving boardId parameter.


I'v also tried both of them with boardID instead of boardId just in case that it was the *name* of the parameter instead of the *shortcode* of it.


Thanks for your help as always.


Best,

Ignacio


Looking into it,


Omar

Hey,


So to successfully call a log event request:


   

var req = RTSession.newRequest()
        .createLogEventRequest()
        .setEventKey("getBoard");
    req.setboardid("1");
    req.setPlayerId(packet.getSender().getPlayerId())
        .send(function(response){
            RTSession.getLogger().debug(response);
        });

   

Your attributes NEED to be lowercase. Also you need to include set infront of your attribute name IN CODE (DO NOT include set in the attribute name in the event configuration. settest in config name will be setsettest in code)

The reason for this is that the function that constructs the JSON looks for the word 'set' to start creating the JSON. For example setEventKey or setPlayerID then lowercases it and includes it in the JSON to send.

I was unaware of this until the dev team cleared it up. It will reflect in the docs soon. 


Hope this helps,

Omar

Hey Omar,


Working as intended!! Thank you very much :).


Just for you to know: Naming the parameter as boardId (capital i) I could call the set as:


req.setBoardId


It makes sense, it just lowercase the first letter after 'set' to maintain the camelCase.


You're awesome as always.


Thanks and best,

Ignacio

Cheers for the info about the lowercase, will be helpful to know!


And you're welcome as always!


Omar

Hello


Could I too have a look at that RTTest sample game?

Thanks in advance.

Login to post a comment