Be a Supporter!

Browse Sections

Newgrounds Wiki: 04 - Handling Returns

In the previous tutorial, we made a few calls to the Event.logEvent component. In the first example we made a single call, and should have gotten a response similar to:

{

"success": true,

"app_id": "test",

"result": {

"component": "Event.logEvent",

"data": {

"success": true,

"event_name": "test event"

}

}

}


In that example, we sent a single call, and got back a single "result" object. The result object has two properties. The "component" property tells you which component was called, and the data property is an object containing any data the component sent back.

Inside the result object, you will always find a success value. This success value is independent of the success value on the outer "output" object (it's possible that your input object is good, but one of your calls was bad).

Let's try posting the call again, but change the "event_name" parameter from "test event" to "oh-noes-this-is-a-bad-event". The output object is still successful, but our result is not:

{

"success": true,

"app_id": "test",

"result": {

"component": "Event.logEvent",

"data": {

"success": false,

"error": {

"message": "Invalid custom event name: \"oh-noes-this-is-a-bad-event\"",

"code": 103

},

"parameters": {

"event_name": "oh-noes-this-is-a-bad-event",

"host": "www.somesite.com"

}

}

}

}


When a call has a false success, the results object will have an "error" object and a "parameters" object that regurgitates the parameters you sent to the component.

The other two examples from the previous tutorial showed you how to make multiple calls in a single input object. In the first method we put multiple call objects into an array. In this server response the result property would be an array of "result" objects:

{

"success": true,

"app_id": "test",

"result": [

{

"component": "Event.logEvent",

"data": {

"success": true,

"event_name": "test event"

}

},

{

"component": "Event.logEvent",

"data": {

"success": true,

"event_name": "test event 2"

}

}

]

}


In the last example, we showed you how to pass an array of parameters to a single component. This server return would make your result.data property an array of "data" objects.

{

"success": true,

"app_id": "test",

"result": {

"component": "Event.logEvent",

"data": [

{

"success": true,

"event_name": "test event"

},

{

"success": true,

"event_name": "test event 2"

}

]

}

}