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 / Send data to HTML AGK app ?

Author
Message
Arbrakan
13
Years of Service
User Offline
Joined: 10th Oct 2010
Location: Geneva
Posted: 9th Apr 2017 11:48
Hi everyone,

There is a way to send (or get) data to a html agk app, via JS or else ?

Like a JSON array.

Thanks for the halp.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 9th Apr 2017 12:22
Can't really push the data to the app without being connected to a server, but your app can certainly pull the data.

Here's a brief example with a code snippet at the bottom of the page. It's for an online high score database, which can show you how to send and receive data with a web server.
http://purpletoken.com/faq.php

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Arbrakan
13
Years of Service
User Offline
Joined: 10th Oct 2010
Location: Geneva
Posted: 9th Apr 2017 12:33
Thanks a lot for your help.

The writefile / readfile doesn't work in HTML5, there is no localstorage with agk ?

Your code seems to be the good way to go, thanks.

Dybing
13
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 10th Apr 2017 21:47 Edited at: 11th Apr 2017 06:45
Here's an example from my current project - an API call to a backend for retrieving one of two lists:



I send the function the mode (0 or 1) that determines what list I want to retrieve from the server. The IP address of the server is externalized into a file rather than hardcoded. I got another function to read that file, and transfer the IP address into the variable ip.addressAV. In actuality, I use a microservices architecture for the backend, so I got several ip addresses, hence it is stored in a type. This makes it easy to target testing servers or production servers without having to recompile and redeploy. But details. Anyhow, I also got a global called httpOK into which I store whether or not the connection is good. This is for later to ensure the app do not crap out on me should for some reason the backend not be reachable. Error checking is what separates a seasoned programmer from a gambler

Later on, whatever is returned from the previous function, is fed into this one (the 's as string' argument):



As you can see, here the error checking happens for if the transfer went through ok. If httpOK is true, it'll print the string fed into the function. If not, it'll display an error message.

Sending data to a backend is much the same process. Just add it to the payload of the SendHTTPRequestASync() method and have the server respond with an ok or error and act on that.

true and false is by the way set earlier as predefined global constants (using #constant) of 1 and 0 respectively. AppGameKit do not have boolean as a standard type, so have to cheat using an integer instead...

Login to post a reply

Server time is: 2024-09-30 01:25:44
Your offset time is: 2024-09-30 01:25:44