0 votes

I am making the HTML5 game with godot engine. and API server using nodejs/expressjs.

here is my code to save the score once game is over.

func game_over():
$EndSound.play()
playing = false
$GameTimer.stop()
$Timer.stop()
set_process(false)
var time = OS.get_datetime()
var milisec = OS.get_ticks_msec()
playerscore.uid =  Hanzo.user_info.id
playerscore.score = score
Hanzo.save_score(playerscore, http) #calling function
for coin in $CoinContainer.get_children():
    coin.queue_free()

$HUD.show_game_over()
$Player.die()

and here is the function for saving the score on cloud Firestore function

func save_score(fields: Dictionary, http: HTTPRequest) ->void:
   var url := "%s/developers/%s/projects/%s" % [HANZO_API_URL, developer_id, pid] 
   var document := { "fields": fields }
   var body := to_json(document)
   print("saving doc.");
   var error = http.request(url, _get_request_headers(), false, HTTPClient.METHOD_POST, body)
   if error != OK:
      push_error("An error occurred in the HTTP request.")

first time started the game play then game over -> saved score successfully.
after game over I play again the game over-> I got this error message in my chrome console log error.

index.js:8 ERROR: Condition "requesting" is true. Returned:
ERRBUSY index.js:8 At: scene/main/httprequest.cpp:90:request() -
Condition "requesting" is true. Returned: ERR_BUSY

Any recommend to handle this error?

Godot version 3.2.3
in Engine by (29 points)
recategorized by

1 Answer

0 votes
Best answer

Sorry everyone, i have fixed this issue .

Why this happen?

When I submitted the request to server nodejs I need to return with success status code.
so the server will response success instead if pending which mean server is busy and that is the reason make gogot return the ERR_BUSY

for my case , I need to something like this:

App.post('/save_score', function(req, res) {
        const result = ref.update(update_data); // update existing the document
        res.status(200).send({id: result.id, "state": true});
    });
by (29 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.