3. SubmitScore Event

3. SubmitScore Event

This event is responsible for submitting the game score to the server when the game ends. The game client should trigger this event when the game ends along with its parameters like score, scene_name, time etc.

  • Arguments should be provided by the game client and can be built using following approach: Create a Dictionary - Dictionary<string, IList> scoredata = new Dictionary<string, IList > (); This dictionary has the following Lists added to the IList

    • List<string> scenename - Pass WinZO’s game scene name. SceneNames class is present in WinZO’s SDK. Use SceneNames.WINZO_GAME_SCENE.

    • List<int> time - Time taken by user. i.e for how much time the user has played the game. Total time is provided by the WinZO server in config. You need to calculate elapsed time and pass it to this parameter.

    • List<int> opponentScore - If your game is a multiplayer game then you need to send the opponent score as well, It should not be the score array rather it should be the total score of the opponent player. eg. 55, it should be of Int type.

    • List<ObscuredInt> scores - It is the score array of the local player. Its type should be ObscuredInt. scores should be an array in which every element contains score increase or decrease (delta) whenever there is a change in score. For example, If a player collects a coin and it gains +5 points, then +5 will be added to this array and call WinZO’s UpdateScore function with the current score of the game to display the score on the UI. If a player collects poison, then -5 will be added to this array. This array is sent in the submitScore event.

public List<ObscuredInt> winzoscores = new List<ObscuredInt>(); // score array
int expectedScore; // delta 
private ObscuredInt score = 0; // current score

public ObscuredInt Score
{						
    get { return score; } 
    set
    {
         expectedScore = (value - score); 
         winzoscores.Add(expectedScore); // added in score array
         score = value;
         WinzoScoreTracker.UpdateScore(score, expectedScore); // send update score
    }						
} 

How to Use SubmitScore

public void GameOver() 
{ 
   Dictionary<string, IList> scoreData = new Dictionary<string,IList > (); 
   //Mandatory Keys 

   //Add Scene Info 
   List<string> scenename = new List<string>();
   scenename.Add(SceneNames.WINZO_GAME_SCENE); 

   //Add Time Elapsed Info 
   List<int> timelist = new List<int>(); 
   timelist.Add(timeElapsed); 
   
   //Add Player Score Array 
   List<ObscuredInt> score = scores; 


   //Add all opponent player scores, you will get opponent ids in SetUpGame Event Data
   List<object> oppoPlayerScores = new  List<object>();

   //1st opponent 
   
   MultipleOpponentScore oppoPlayerScore1 = new MultipleOpponentScore(opponentId1,
   opponentScore1);  
   oppoPlayerScores.Add(oppoPlayerScore1); 
   //2nd opponent 
   MultipleOpponentScore oppoPlayerScore2 = new MultipleOpponentScore(opponentId2, 
   opponentScore2);  
   oppoPlayerScores.Add(oppoPlayerScore2); 
   //Add Game Logs //Read next section for more details
   List<string> allGameData = new List<string>();

   scoreData.Add(IntegrationEvents.SceneName, scenename);
   scoreData.Add(IntegrationEvents.Scores, score); 
   scoreData.Add(IntegrationEvents.TimeElapsed, timelist);
   scoreData.Add(IntegrationEvents.GameData, allGameData);
   scoreData.Add(IntegrationEvents.OppPlayerScore, oppoPlayerScores);  
   WinzoEventManager.TriggerEvent(IntegrationEvents.SubmitScore,scoreData); } 

Last updated