Swarkin / Godot-AwaitableHTTPRequest

Addon to ease the usage of HTTP Requests in Godot
52 stars 6 forks source link

The example, as is, is insufficient #4

Closed 100307009 closed 2 months ago

100307009 commented 2 months ago

The example provided in the source

extends Control
@export var http: AwaitableHTTPRequest

func _ready() -> void:
    var r := await http.async_request('https://api.github.com/users/swarkin')

    if r.success:
        print(r.status_code)              # 200
        print(r.headers['Content-Type'])  # application/json
        print(r.json['bio'])              # fox.

throws following error: Invalid call. Nonexistent function 'async_request' in base 'Nil'.

Adding something like

    http = AwaitableHTTPRequest.new()
    add_child(http)

or an explicit mention that it requires an existance of a node AwaitableHTTPRequest in the scene. This should be useful for less experienced audience

Swarkin commented 2 months ago

I think once you get into the networking territory, especially when looking for extra addons, you should know how to fill out a @export variable, however I'll add a notice.