Adventure Game Studio

AGS Support => Modules, Plugins & Tools => Topic started by: Dorcan on Tue 23/08/2005 13:44:23

Title: PLUGIN: FileNet - Send data to web pages
Post by: Dorcan on Tue 23/08/2005 13:44:23
Mmh I made an "internet" plugin for a test game (an online chess game...). The plugin is not yet finished, but 5 functions are operational:

void InitPostContent();
void AddPostContent(string variable, string content);
string SendWebPostMethod(string url, string action);
string ReadWebContent(string url, string action);
string SaveWebImage(string url, string action, string destFile);


The first three functions work the way an html form works, with the POST method:

- InitPostContent will initialize variables and values.

- AddPostContent will add a variable containing a value.
Example:
AddPostContent("test", "a value"); would work the same way as a form object in a web page :
<input type="hidden" name="test" value="a value">


- SendWebPostMethod simply submit variables and values to an url, the same way a form works, and then returns the page content as a string.
Example:
SendWebPostMethod("http://www.test.com/score.php", "?action=newscore"); would work the same way as if you submited a form with these parameters:
<form action="http://www.test.com/score.php?action=newscore" method="POST">


- ReadWebContent returns the content of a web page.
Example:
   String buffer;
   StrCopy(buffer, ReadWebContent("http://www.test.com/ags/agssave.001", "") );
   File *output = File.Open("agssave.001", eFileWrite);
   output.WriteRawLine(buffer);
   output.Close();


This will copy the agssave from a website into the game folder.
Note: You could do the same thing with SendWebPostMethod as it also returns the url content.


- SaveWebImage will copy an image from an url into your game folder :
Example:
   DynamicSprite * avatar;

   SaveWebImage("http://www.test.com/images/avatar.bmp", "", "data/avatars/avatar.bmp");
   avatar = DynamicSprite.CreateFromFile("data/avatars/avatar.bmp");
   if (avatar != null) {
      RawDrawImage(150, 100, avatar.Graphic);
      avatar.Delete();
   }



You'll find more info in the zip file.


ags_filenet.zip, 145ko
Download
(http://www.digitalmindstudio.ch/fichiers/divers/ags_filenet.zip)


Title: Re: Sending and displaying variables on my website
Post by: Kweepa on Tue 23/08/2005 14:20:30
Wow, fantastic work!
What else did you have planned?
Title: Re: Sending and displaying variables on my website
Post by: Menaze on Tue 23/08/2005 15:28:19
Wow Dorcan, thats awesome!!!

That plugin is great. I will try it out. Also I'm curious how this will develop. There's quite a lot potential in this plugin.
Man, I think I will try to learn to make plugins, too. This increases everybodys options to the max... 

Well, I think I'm busy now... Thank you
Title: Re: sending high score to a web page
Post by: Andrechan on Thu 07/09/2006 21:37:58
I've tried this plugin. It seems good but if I try a simple script

String name=lblName.Text;
String p=lblPunteggio.Text;
AddPostContent("name", name);
AddPostContent("points",p );
  SendWebPostMethod("http://pexta.altervista.org/score.php");

there is the error
"Cannot convert String* to string"
I can't use "string" because this data type is not supported in 2.72
What can I do?
Is there a way to edit the plugin?
Title: Re: sending high score to a web page
Post by: monkey0506 on Thu 07/09/2006 22:03:38
Uncheck "Enforce new-style Strings" in the Game Editor which will allow you to use strings.

string name, p;
StrCopy(name, lblName.Text);
StrCopy(p, lblPunteggio.Text);
AddPostContent("name", name);
AddPostContent("points", p);
SendWebPostMethod("http://pexta.altervista.org/score.php");
Title: Re: sending high score to a web page
Post by: Andrechan on Thu 07/09/2006 22:33:53
Thanks, but now it says
"cannot convert from const string to string"Ã,  ???

I hate all these string types :-[
Title: Re: sending high score to a web page
Post by: monkey0506 on Thu 07/09/2006 22:34:55
What line gives you that error (what code is on the line)?
Title: Re: sending high score to a web page
Post by: Andrechan on Thu 07/09/2006 22:45:37
All these two

>AddPostContent("name", name);
>AddPostContent("points", p);

And the next was wrong (One parameter instead of two) but if I put two parameters
>SendWebPostMethod("http://pexta.altervista.org/score.php","?random=3");
there is still the const string problem ;__;
Title: Re: sending high score to a web page
Post by: SSH on Fri 08/09/2006 12:47:03
Try:


string name, p, lname, lpoints, url, thingy;
StrCopy(name, lblName.Text);
StrCopy(p, lblPunteggio.Text);
StrCopy(lname, "name");
StrCopy(lpoints, "points");
StrCopy(url, "http://pexta.altervista.org/score.php");
StrCopy(thingy, "random=3");
AddPostContent(lname, name);
AddPostContent(lpoints, p);
SendWebPostMethod(url, thingy);