Triggering an event once post response received?

In a nutshell, I’m posting an email address to an external URL that will either return canplay=true or canplay=false (as well as a few extra variables - in JSON format.)

I’m parsing the response into variables which seems to work just fine, but in the first scene (where the email address is entered) I’m not sure how to trigger a “Change to Scene” only when that variable has actually been returned from the POST request.

If I just add a condition checking the variable to the events panel it doesn’t work, presumably because it’s checking that condition right away before the post response is in.

A ‘while’ event sounded promising, but I can’t make any sense of the documentation on the wiki or so much as find anything that says ‘while’ in events anywhere (I thought maybe after the POST something could keep repeating WHILE the variable was empty, but if that’s an option I’m not understanding how to set it up.)

If anyone can point me in the right direction it’s much appreciated.

Hmmm…do you have any examples of what your variable will look like with a post response?

I want to say it’ll either be 200 or the actual data. Which can change what your next steps are.

As far as I remember, requests made by GDevelop are blocking, meaning that the game and the event sheet execution will freeze until the request is finished. So you can check the variable directly after the request and it should work :wink:

1 Like

I think you must do the variable compare when you receive the POST request in the same event not in a separated event, anyway some screenrshots of your events could help us to undersatand.

Thanks all, it turned out I had a scope problem with the variables.

Basically I had retrieved my response in JSON format, converted that into variables, then was trying to check against those variables using ‘Value of a scene variable’

VariableString(returnedVars.canPlay) = 1

I guess at that point it wasn’t a global or scene variable (I tried both,) so it wouldn’t pass that check.

Anyway - for now I’ve just made placeholder global variables which I’m changing the values of with what’s in the POST response, then using the values of those global variables afterwards (which works just fine, though I’m not sure if there was a better way to check it without having to do the extra step.)