Events allow you to define custom data structures that you want to pass into the GameSparks service and thereby provide the means for you to achieve precisely the behavior you want for your players when you build your game. When you create an Event in the Configurator, you'll notice that it's duplicated and listed on the Cloud Code page Scripts panel under both Events and Challenge Events - why is this?


Events are given this dual presentation in anticipation of the differing use cases you might want to achieve for your game using an Event and it's attached Cloud Code:

  • Events are meant to be used as the vehicles for custom logic you want to pass into the service to achieve your more general use cases and development purposes - such as when posting a score to a leaderboard or retrieving data about the player. You use the LogEventRequest for these Events. This request requires a single eventKey¬†parameter, which is the Short Code you have given the Event.
  • Challenge Events are meant to be used as the vehicles for custom logic you want to pass into the service for your use cases and development purposes that involve the context of a Challenge in your game. You use a LogChallengeEventRequest for these Challenge Events. This request requires two parameters: the eventKey parameter, which is the Short Code you have given the Event; the challengeInstanceId of the Challenge for which you want your Cloud Code to have access. The advantage with this approach is that the Cloud Code you attach to a Challenge Event will automatically have access to the context of a Challenge when submitted through a LogChallengeEventRequest. This can be very helpful and convenient, because it will reduce the Cloud Code you will need to access the desired Challenge.
  • Note that, if you wish to do so, you can ignore the convenience of using a Challenge Event for your Challenge use cases and access a Challenge instance from a LogEventRequest using calls from your Event Cloud Code to the SparkChallenge API.