PHP SDK: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
__NOTOC__
You can access the MTA Web Interface from almost any programming language that can request web pages using HTTP POST and encode and decode [[JSON]].
You can access the MTA Web Interface from almost any programming language that can request web pages using HTTP POST and encode and decode [[JSON]].



Revision as of 00:10, 5 July 2007

You can access the MTA Web Interface from almost any programming language that can request web pages using HTTP POST and encode and decode JSON.

PHP can do this very easily! This SDK provides one function "callFunction" that will allow you to call any exported script functions on any server that you have access to.

The download below includes two example pages - one that shows a simple scoreboard, the other that shows the automatic handling of element and resource objects.

Functions

callFunction

Syntax:

[php]
returns[] = callFunction ( "hostname:httpPort", "resourceName", "functionName" [,args...]);

Examples

[php]
include ( "mta.php" );
$retn = callFunction ( "bastage.student.utwente.nl:33004", "echobot", "getThisResource" ); // $retn is an array containing the values the function returned
$resource = $retn[0]; // the first returned value is the resource
$retn = callFunction ( "bastage.student.utwente.nl:33004", "echobot", "getResourceName", $resource ); 
$resourceName = $retn[0]; // contains the name of the resource 'echobot'

Caveats

  • This only supports PHP 5.0.
  • You cannot currently compare two Resource or Element instances that you expect to be identical - you need to do a "deep compare", comparing either the "id" fields or the "name" fields.

Download