Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Can I pass a php function through AGK?

Author
Message
Kobaltic
12
Years of Service
User Offline
Joined: 24th Jan 2012
Location: PA, USA
Posted: 3rd Mar 2013 03:18
I setup my php site and connected to my database. I can now call a php page that cause an update to my database. I want to pass a function from AppGameKit to php and eventually pass an argument with it. I tried to send it as raw data through the sendhttpReuest command but it didn't work. Any ideas?
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 3rd Mar 2013 03:33 Edited at: 3rd Mar 2013 03:34
AGK sends data via POST. So, you can include whatever data along with the HTTP request and process it via PHP as a regular POST submission (e.g., $_POST["varname"])

For example, you can create a temporary string to concatenate all of the data you wish to send in AppGameKit before making the request:

HTTPData$ = "Var1=" + Str(Var1Val) + "&" + "Var2=" + Str(Var2Val)

Then when you make the request, you can use:

SendHTTPRequestASync(ConnectionID, URL$, HTTPData$)

If URL$ is "mydomain.com/script.php" then the actual request will be made to "http://mydomain.com/script.php?Var1=5&Var2=10"

From there you just use the standard PHP commands to parse the information, save to database etc.

To get data back to AppGameKit from PHP, the easiest way is to echo it out in the PHP script and then use GetHTTPResponse(...)


(SendHTTPRequest uses the same format as SendHTTPRequestASync)
Kobaltic
12
Years of Service
User Offline
Joined: 24th Jan 2012
Location: PA, USA
Posted: 3rd Mar 2013 05:08
Thanks that helps me out.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 3rd Mar 2013 17:29
The short answer is 'No', you can not call a specific PHP function from AGK. You can only post to a file and let it handle everything.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Kobaltic
12
Years of Service
User Offline
Joined: 24th Jan 2012
Location: PA, USA
Posted: 3rd Mar 2013 18:37 Edited at: 3rd Mar 2013 18:47
I ended up just passing a var through, then doing a simple check to see if the var = 1 then call the function. It works. Not sure if there is a better way but it gets the job done.




Edit: what is the difference between httpRequest and httpRequestASync
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 3rd Mar 2013 18:58 Edited at: 3rd Mar 2013 18:58
That's the best approach, Kobaltic. This is how virtually every language communicates with PHP I imagine--the client passes in data via GET/POST and then PHP parses the input to execute whatever functions it needs.

httpRequestASync will call the request in the background (asynchronously) so it does not lock up the rest of the app while the request is pending. This makes it possible to submit scores to a server, retrieve high scores, and so on without causing any noticeable delay to the user who can continue playing the game as this happens.

Checking for when the async call is complete is pretty straightforward using GetHTTPResponseReady(). What I do is set a variable (e.g., HTTPRequestPending) to 1 when the async request is called, and then do the following in the main loop (assuming that the HTTP connection is named HTTPConnection).

Kobaltic
12
Years of Service
User Offline
Joined: 24th Jan 2012
Location: PA, USA
Posted: 3rd Mar 2013 19:37
Thanks, you even beat me to my next question. I got it to come back with my correct response. Yeah now I can move on to the real stuff.
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 3rd Mar 2013 19:50
I just want to say thanks xCept. Will make my work a bit easier when I need to get back to PHP and making it work with AppGameKit


Demo 3 is out now!
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 3rd Mar 2013 19:56
The way to pass back data from your PHP script is to end it with the 'echo' command on a line something like:


Make sure that is the very last executed line in your PHP script.

There is virtually no limit to what you can return that way. But it shouldn't contain any carriage returns.

I do thinks like: $res = '1|'.join('|',some_array)

This lets me return complete sets of data separated by the '|' character. Then you split the return value on that character and process the data. My current WIP will return all of the stored game play stats for a player when they reconnect from a new device or reinstalled app to the game site.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Kobaltic
12
Years of Service
User Offline
Joined: 24th Jan 2012
Location: PA, USA
Posted: 3rd Mar 2013 20:54
I like that idea of grouping info in one call. it should really speed things up.
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 3rd Mar 2013 22:06
Can AppGameKit retrieve more than 255 characters (a full string) in one call?

BTW have you tried using CountStringTokens() and GetStringToken() in AppGameKit? Those commands makes it very easy to parse strings split up by specific characters.


Demo 3 is out now!
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 4th Mar 2013 00:29
As far as I know, there isn't a limit on what can be retrieved. I haven't seen anywhere that limits a string to 255 characters.

At this point, I am working in Tier 2 and use some basic C++ stuff to parse my string into a set of strings.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 4th Mar 2013 01:30
Quote: " Can AppGameKit retrieve more than 255 characters (a full string) in one call?"


GetHTTPResponse will return the complete contents of the request--so whatever is output from the PHP script will be returned, regardless of its size.
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 4th Mar 2013 08:49
I would assume that strings in T1 are limited to 255 characters just like DBP. Or am I wrong about that?


Demo 3 is out now!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 4th Mar 2013 09:16
I just checked a text object I'm using in Hide It Find It and it has over 5000 characters in a single text object so the limit is much higher than 255 you'll be glad to hear


this.mess = abs(sin(times#))
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 4th Mar 2013 11:24
Not that I need it anywhere in my game, but it's good to know


Demo 3 is out now!

Login to post a reply

Server time is: 2024-05-07 04:24:41
Your offset time is: 2024-05-07 04:24:41