Integrate gaming data storage

Models and controllers

SC_User models Scoreloop users. Instances of SC_User have access to the unique Scoreloop user identifier and user login.

Each user has a "user context", which consists of additional data that a game developer can define, per game, and which can be stored on the server and retrieved as necessary. Ensure that the data is a dictionary of Strings. Scoreloop does not limit the size of the data, although we recommend keeping it to a minimum so as to not reduce your game's optimal playability.

Controller Tasks
SC_UserController
  • Sets user context

  • Retrieves a single user’s context

  • Updates a single user’s context

Basic integration

The code below shows how additional "experience points" can be associated with a user and stored in the user context. This data is not a part of score that the user may achieve and does not affect the position of the user on any leaderboard.

Submit user context

  1. Create the user context and assign the experience points.
  2. Get an instance of the SC_UserController.
  3. Get an instance of the SC_User object.
  4. Set the experience points in the user context by calling SC_User_SetContext().
  5. Set the user of the SC_UserController to the user object created above by calling SC_UserController_SetUser(). This worked only for the session user.
  6. Submit this data to the server by invoking SC_UserController_UpdateUserContext().
// Assumes exp_points is the skill value/experience points attained by the user in the game.
SC_String_h points;
SC_Error_t errCode;
SC_Client_h client;
SC_User_h myUser;
SC_UserController_h myUserController;
SC_Context_h myContext;

errCode = SC_String_New(&points, "123");

//Step 1
errCode = SC_Context_New(&myContext);
// points is the const char string to which we assign the experience points
SC_Context_Put(myContext, "points", points);

//Step 2
// client - assumes the handle to the client exists
// aCallback is the callback to be registered
errCode = SC_Client_CreateUserController(client, &myUserController, aCallback, aCookie);

//Step 3
// Get the current session user
// mySession -  assumes the handle to the current session exists
myUser = SC_Session_GetUser(mySession);

//Step 4
// myContext
errCode = SC_User_SetContext(myUser, myContext);

//Step 5
errCode = SC_UserController_SetUser(myUserController, myUser);

//Step 6
errCode = SC_UserController_UpdateUserContext(myUserController);

Retrieve user context

  1. Get an instance of the SC_UserController.
  2. Call SC_UserController_LoadUserContext() using the UserController that was created.
  3. Await a successful server response using the callbacks.
  4. After a successful request, in the callback, call SC_User_GetContext() to retrieve the user context.
  5. Access the required data from the context object.
SC_String_h points;
SC_Error_t errCode;
SC_Client_h client;
SC_User_h myUser;
SC_UserController_h myUserController;
SC_Context_h myContext;

//Step 1
// client - assumes the handle to the client exists
// aCallback is the callback to be registered
errCode = SC_Client_CreateUserController(client, &myUserController, aCallback, aCookie);

//Step 2
SC_UserController_LoadUserContext(myUserController);

//Step 3 & 4
// To be written by the developer: wait for server response
// Get the current session user in the callback
// mySession -  assumes the handle to the current session exists
myUser = SC_Session_GetUser(mySession);
myContext = SC_User_GetContext(myUser);

//Step 5
// aExp_points is the const char string for which to retrieve the value
// points is the experience points stored in the user context that will be retrieved.
errCode = SC_Context_Get(myContext, "points", &points);

Challenge and score context

  1. A context can be attached to a challenge to hold seed data for example, passing the game level of the contender to the contestant, or the time taken to complete the challenge to boost competition. Take a look at SC_Challenge_GetContext() and SC_Challenge_SetContext() to learn more about the functionality.
  2. A score context can be used to pass ghost replays where a user can retrieve ghosts of other user's gameplay to compete against them. SC_Score_GetContext() and SC_Score_SetContext() are methods of interest to implement gameplay ghosting.

Click here to see if your implementation covers the essential features.

Last modified: 2014-05-14



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus