Jump to content


Photo

Asynchronous Functions


  • Please log in to reply
74 replies to this topic

#21 Mike.Dailly

Mike.Dailly

    Evil YoYo Games Employee

  • Administrators
  • 1494 posts
  • Version:GM:Studio

Posted 14 March 2012 - 01:22 PM

We did consider the system variable route, but decided against that for a few reasons. On top of this, it allows for easy expansion if we want to add more things into the map (or dictionaries as everyone else calls them!).

The status and ID should be reals anyway....?

When doing loading/requests.... the lookup isn't exactly the time sink. :rolleyes:
  • 0

#22 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 2859 posts
  • Version:GM:Studio

Posted 15 March 2012 - 03:15 AM

I like this new async system, but not for http requests, for a couple reasons:
_ You cant know the request status until it finished.
_ You cant know how many bytes have been loaded (to create loading bars and such, wich is the best advantage of async).

basicaly you have no idea of what happened to the function until it ends.. and if it fails you are clueless..

Wouldnt it be better to create a ds_map right after you call the async function, and have the ds_map to tell you whenever the request ended and its return values? this way you can keep track of the information at all time :)
  • 0

#23 Mike.Dailly

Mike.Dailly

    Evil YoYo Games Employee

  • Administrators
  • 1494 posts
  • Version:GM:Studio

Posted 15 March 2012 - 01:19 PM

Don't be silly, HTTP loading takes forever, and if we blocked it would cripple the game! :turned:

If you need to know how much to load, then either work it out before hand, or write some PHP that will return it quicker. Either way, this is the way you HAVE to do it - you can't block a game for 30 seconds for one file to come down.

And if it fails, you still get the callback, complete with the ID and the error! You shouldn't need any more!
  • 0

#24 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 2859 posts
  • Version:GM:Studio

Posted 15 March 2012 - 06:39 PM

Nono, im not saying to block it, i'm saying to still have it the asynchronous way, but get rid of the event, and just use a (maybe read-only?) ds_map to retrieve the needed info about it.. the same way some DLL's currently do it.

for example:
async = http_get(url);

then on step event:
if (ds_map_read(async,"status") == 200) {
    result = ds_map_read(async,"result")
}

That way you get rid of having to check who called the async event on the first place, and you can have many kinds of information being loaded onto the ds_map, like kbs or competion ammount, assumming, of course, that GameMaker can handle ds_maps this way :)

Edited by Manuel777, 15 March 2012 - 06:42 PM.

  • 0

#25 Mike.Dailly

Mike.Dailly

    Evil YoYo Games Employee

  • Administrators
  • 1494 posts
  • Version:GM:Studio

Posted 16 March 2012 - 10:31 PM

The problem is, this is terribly inefficient. You would end up with LOTS of "IFs" through the code testing for stuff loading or not. Callbacks/Events are much more efficient as it allows you to only execute the code you need to, WHEN you need to.

We will be heading more this way in the future, polling is terrible and slowly drains CPU power, which while not an issue on PCs, can be a killer on mobiles.
  • 0

#26 locohost

locohost

    GMC Member

  • GMC Member
  • 459 posts
  • Version:GM:Studio

Posted 18 March 2012 - 05:13 PM

I have some test code for this. I made a simple hello.php script the does exit("Hello!").

The Async Event is firing as expected. I'm looking in the async_load map and nearly all the variables look corrected except for the most important one "result". ds_map_find_value(async_load,"result") is returning nothing. I'm expecting it to contain "Hello!" and it doesn't.

1. "url" has the correct url
2. "result" is blank
3. "http_status" has 0
4. "id" has the right id
5. "status" has -1

Does the -1 status indicate some sort of http result failure?

Can anyone think what's going wrong?

Thanks for your advice :smile:
  • 0

#27 Mike.Dailly

Mike.Dailly

    Evil YoYo Games Employee

  • Administrators
  • 1494 posts
  • Version:GM:Studio

Posted 19 March 2012 - 04:27 PM

For those who are having difficulty getting anything to work, I've done a little example, and we've enabled a server page with full cross domain enabled.

You can get the demo here: http://store.yoyogam...st_get_demo.gmz

This demo will return a JSON string with the parameters you supplied in the post/get. if no parameters are sent, it'll return a very simple "request succeeded" response.

You can use this URL ( http://www.yoyogames.com/crossdomain )to test your own code, and if it returns okay, then the server your going to does NOT have cross domain enabled, which means your game/app would have to live directly ON that server to work.

Native applications don't have this issue, it's the browser+server that is limiting cross domain access to help combat scripting hacks.
  • 0

#28 locohost

locohost

    GMC Member

  • GMC Member
  • 459 posts
  • Version:GM:Studio

Posted 19 March 2012 - 04:43 PM

So you're thinking it's a cross domain issue? I will certainly try your test app this eve. However, I'm running everything locally on a wampserver in one folder. The game code and server scripts are all together. One thing that is different on my setup is I'm using localhost:81. Is there a problem with the port maybe?
  • 0

#29 alexandervrs

alexandervrs

    GMC Member

  • GMC Member
  • 423 posts
  • Version:GM:Studio

Posted 19 March 2012 - 04:49 PM

This demo will return a JSON string with the parameters you supplied in the post/get

Speaking of JSON, will there be functions like string_json_encode and string_json_decode to help parse json strings, like in PHP?

And a second question concerning the example, when I ran it as Windows executable it didn't return any value, HTML5 worked of course. Being able to do requests from a desktop application would be useful as well in order to post scores or authenticate accounts. Is this planned or will it be coming along when multiplayer is done?

Edited by alexandervrs, 19 March 2012 - 04:49 PM.

  • 0

#30 rwkay

rwkay

    YoYo Games CTO

  • YoYo Games Staff
  • 1414 posts
  • Version:Unknown

Posted 19 March 2012 - 04:53 PM

Http_get and http_post_string - work across all platforms when it does not it is a bug, be careful of firewall issues though and check the http_status that is coming back...

Edit: Mike has just found a bug with passing parameters on the URL under windows, we are currently looking at it.
  • 0

#31 Dark Matter

Dark Matter

    RPG Expert

  • GMC Member
  • 3196 posts
  • Version:GM:Studio

Posted 19 March 2012 - 05:06 PM

Could someone explain a little more how http_post_string works? How does it send that additional data? Under what "name"? How can I get it from the $_POST data on my webpage?
  • 0

#32 gnysek

gnysek

    GMC Member

  • GMC Member
  • 324 posts
  • Version:GM:Studio

Posted 19 March 2012 - 05:26 PM

So you're thinking it's a cross domain issue? I will certainly try your test app this eve. However, I'm running everything locally on a wampserver in one folder. The game code and server scripts are all together. One thing that is different on my setup is I'm using localhost:81. Is there a problem with the port maybe?


when you're entering URL to browse any site ont that localhost, is it http://localhost:81/ or just http://localhost/ ? Then, when you're executing that from GM, you're using exactly same protocol, host name and port ?
  • 0

#33 scurvycapn

scurvycapn

    GMC Member

  • GMC Member
  • 172 posts
  • Version:GM:Studio

Posted 19 March 2012 - 05:42 PM

I'm seeing some odd behaviors on this using http_get(). I have an extremely basic php script that does nothing but echo the IP address of the client. I edited the example to use http_get() and to point to my script. Sometimes it returns back the correct value, and other times it appends a zero on the end. For example, say my IP address was 12.12.12.12. Sometimes I get "12.12.12.12" back and sometimes I get "12.12.12.120". For fun I created another script that returns "1.5" (without the quotes). Once again, sometimes I get "1.5", other times I get "1.50". I did the same with "25" and did occasionally get "250" as the result. These issues do not occur when testing the scripts manually through a web browser. The trailing zeros do not occur if I am returning back text such as "Hello!" or when hitting up a static document such as a txt file containing only a numeric value.

This testing was done in the C++ runner.

Edited by scurvycapn, 19 March 2012 - 05:43 PM.

  • 0

#34 locohost

locohost

    GMC Member

  • GMC Member
  • 459 posts
  • Version:GM:Studio

Posted 19 March 2012 - 06:02 PM


So you're thinking it's a cross domain issue? I will certainly try your test app this eve. However, I'm running everything locally on a wampserver in one folder. The game code and server scripts are all together. One thing that is different on my setup is I'm using localhost:81. Is there a problem with the port maybe?


when you're entering URL to browse any site ont that localhost, is it http://localhost:81/ or just http://localhost/ ? Then, when you're executing that from GM, you're using exactly same protocol, host name and port ?



The wampserver is running on port 81. I currently have a JS extension that manages the comms from the Html5 game to the PHP server scripts. It all works fine, but I'd love to start using this new http_get so I can eliminate a layer of complexity. That being the extension and JS :smile:

I just mentioned the port above in case there could be something in the http_get code that is accidentally stripping that or not handling it correctly :smile:

EDIT: Ran the demo. It works. But is that a PHP script or just Html? Also, it's obviously port 80 so I still have my non-80 variable to consider.

Does anyone know what my returned "status" = -1 and "http_status" = 0 means? I'm assuming these indicate some reason why my "result" is blank. I can run the Url in the browser and I see the return result expected.

Edited by locohost, 19 March 2012 - 09:03 PM.

  • 0

#35 True Valhalla

True Valhalla

    ಠ_ಠ

  • Retired Staff
  • 4880 posts
  • Version:GM:Studio

Posted 19 March 2012 - 09:22 PM

I'm only getting -1 status and 0 http_status as well from a URL I know should be returning different values.

I tried Mike's demo and that all seemed to work fine. I guess it's a problem with my host :(

Edited by True Valhalla, 19 March 2012 - 09:40 PM.

  • 0

#36 locohost

locohost

    GMC Member

  • GMC Member
  • 459 posts
  • Version:GM:Studio

Posted 21 March 2012 - 08:38 PM

I'm only getting -1 status and 0 http_status as well from a URL I know should be returning different values.

I tried Mike's demo and that all seemed to work fine. I guess it's a problem with my host :(


Is your web server running on port 80 or other?
  • 0

#37 Destron

Destron

    GMC Member

  • GMC Member
  • 919 posts
  • Version:GM:HTML5

Posted 25 March 2012 - 08:55 PM

If your struggling to get this to work it is because you can not test locally on your PC. You will need to upload your HTML5 game to your web server and try it there.

Since GMS does not let you export the game(create application) and the async events don't work in GM:HTML5 then what you need to do is run your game but don't close it, then look in the compile window to where the temp game is created, will be %AppData%/Local/Temp/gm_ttt_XXXXX/game_name/ and go to that location to get the game and upload it to your web server (or transfer to the www folder of your wamp server).

From there you can run it and get the expected results.

With local testing when I call server side scripts they do what they are supposed to do but the returned results are wrong.

Edited by Destron, 25 March 2012 - 09:18 PM.

  • 0

#38 locohost

locohost

    GMC Member

  • GMC Member
  • 459 posts
  • Version:GM:Studio

Posted 25 March 2012 - 09:01 PM

If your struggling to get this to work it is because you can not test locally on your PC. You will need to upload your HTML5 game to your web server and try it there.

Since GMS does not let you export the game(create application) and the async events don't work in GM:HTML5 then what you need to do is run your game but don't close it, then look in the compile window to where the temp game is created, will be %AppData%/Local/Temp/gm_ttt_XXXXX/game_name/ and go to that location to get the game and upload it to your web server (or transfer to the www folder of your wamp server).

From there you can run it and get the expected results.


Have you ever installed a web server on your laptop? It's quite easy. Wampserver is one very simple way. My game is running in a folder on my local web server right beside the PHP scripts. I can call them just fine from my Javascript extension. But I'd like to replace the extension and that bit of complexity with http_get. It -might- be because Wampserver is not running on port 80 but so far I can get a comment on that.

:smile:
  • 0

#39 Destron

Destron

    GMC Member

  • GMC Member
  • 919 posts
  • Version:GM:HTML5

Posted 25 March 2012 - 09:19 PM


If your struggling to get this to work it is because you can not test locally on your PC. You will need to upload your HTML5 game to your web server and try it there.

Since GMS does not let you export the game(create application) and the async events don't work in GM:HTML5 then what you need to do is run your game but don't close it, then look in the compile window to where the temp game is created, will be %AppData%/Local/Temp/gm_ttt_XXXXX/game_name/ and go to that location to get the game and upload it to your web server (or transfer to the www folder of your wamp server).

From there you can run it and get the expected results.


Have you ever installed a web server on your laptop? It's quite easy. Wampserver is one very simple way. My game is running in a folder on my local web server right beside the PHP scripts. I can call them just fine from my Javascript extension. But I'd like to replace the extension and that bit of complexity with http_get. It -might- be because Wampserver is not running on port 80 but so far I can get a comment on that.

:smile:


Yes, that was why I mentioned copying to the www folder of Wampserver as well. I do have a local server running in my house that I use but I like to test both my local server and my paid hosting server. Sometimes I get different results. Just wanted to make people aware that running your game from the GM "play button" and calling the scripts from either wamp server or your paid hosting won't return you the expected results.

Edited by Destron, 25 March 2012 - 09:21 PM.

  • 0

#40 locohost

locohost

    GMC Member

  • GMC Member
  • 459 posts
  • Version:GM:Studio

Posted 25 March 2012 - 09:25 PM



If your struggling to get this to work it is because you can not test locally on your PC. You will need to upload your HTML5 game to your web server and try it there.

Since GMS does not let you export the game(create application) and the async events don't work in GM:HTML5 then what you need to do is run your game but don't close it, then look in the compile window to where the temp game is created, will be %AppData%/Local/Temp/gm_ttt_XXXXX/game_name/ and go to that location to get the game and upload it to your web server (or transfer to the www folder of your wamp server).

From there you can run it and get the expected results.


Have you ever installed a web server on your laptop? It's quite easy. Wampserver is one very simple way. My game is running in a folder on my local web server right beside the PHP scripts. I can call them just fine from my Javascript extension. But I'd like to replace the extension and that bit of complexity with http_get. It -might- be because Wampserver is not running on port 80 but so far I can get a comment on that.

:smile:


Yes, that was why I mentioned copying to the www folder of Wampserver as well. I do have a local server running in my house that I use but I like to test both my local server and my paid hosting server. Sometimes I get different results. Just wanted to make people aware that running your game from the GM "play button" and calling the scripts from either wamp server or your paid hosting won't return you the expected results.


Yeah it is running in the Wampserver root :smile: So your simply saying try it on another host to see what happens? I can do that. I might also see if I can get Wampserver running on port 80. It wouldn't when I originally installed on this laptop so I swiched to 81 and that worked. Something was using 80. Not sure what. I'll fiddle with it more locally and on my paid hosting.

Thanks :smile:

EDIT...

And look how smart I am a few posts above! :laugh:

http_get only works on port 80. Is that a feature or a bug? :smile:

EDIT AGAIN...

Or it might be sensitive to switching from "localhost" in the Url then calling 127.0.0.1 in the http_get Url. So http_get thinks localhost and 127.0.0.1 are different domains I guess? Or is Apache and/or PHP thinking they're differetn domains? I'll try port 81 again with "localhost" in both the game Url and the http_get Url...

EDIT 3...

Yes it's that. Port 81 (or any other I imagine) works fine in http_get. The game Url and the Url called by http_get must match exactly. Is Apache and/or PHP causing this block? Is this the "cross domain" issue?

Edited by locohost, 25 March 2012 - 09:58 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users