Skip to content

GameJoltAPIRequest

Simón Olivo (Sarturo) edited this page Nov 18, 2022 · 5 revisions

A GamejoltAPIRequest instance is created by calling a GameJoltAPI Plugin's function.

To receive and process the responses sent by the Game Jolt server, we just connect to its two signals:

  • api_request_completed
  • api_request_failed

Signals

api_request_completed (data: Array)

This signal will be emitted when the request was successfully processed by the Game Jolt Server. This signal will return an Array containing the server response.

api_request_failed (error_message: String)

This signal will be emitted if an error occurs during the sending or processing stage of the request. This signal will return an error message. Error messages include network errors and errors generated by the server.

For more information about network errors, visit the official Godot documentation.

For more information about the Game Jolt API errors, visit the official Game Jolt API documentation.

Example

#Make a request to the GameJolt API, this return a GameJoltAPIRequest Object
var fetch_trophies_request = GameJoltAPI.fetch_trophies({
  "username": GameJoltAPI.username,
  "user_token": GameJoltAPI.user_token
})

#Connect to the GameJoltAPIRequest signals
fetch_trophies_request.connect("api_request_completed", self, "_on_fetch_trophies_completed")
fetch_trophies_request.connect("api_request_failed", self, "_on_fetch_trophies_failed")

#Handle the signals
func _on_fetch_trophies_completed(data: Array):
  #The server sent back an array containing one (or several) objects (dictionaries) with the data described here: https://gamejolt.com/game-api/doc/trophies/fetch
 pass

func _on_fetch_trophies_failed(error: String):
  #If an error occurs this function will be called
 pass