Jump to content


Schalk

Member Since 09 Feb 2008
Offline Last Active Dec 04 2012 06:43 PM

Topics I've Started

HTTP Request Extension

29 December 2011 - 02:28 PM

Posted ImageHTTP Request Extension


This extension package provides networking functionality or ajax magic (I had to use that buzzword at least once in this documentation :P) for GameMaker:HTML5 games. This has been tested on IE, Firefox, Chrome, Opera. Hasn't been tested on any mobile devices.

Functions
Basic - Syncronized
http_get(url,async) - Sends a http get request to the server. url is the link you want to send the request to. async should be false. This will return the response. If the response is an error, an empty string will be returned, "".
http_post(url,params,async) - Sends a http post request to the server. url is the link you want to send the request to. params is the data you want to send, for example, "score=5&name=Bob". async should be false. This will return the response. If the response is an error, an empty string will be returned, "".

Advanced - Asyncronized
http_get(url,async) - Sends a http get request to the server. url is the link you want to send the request to. async should be true. This will return the handle of the request. This will be used to check when the request is ready or if it has can error.
http_post(url,params,async) - Sends a http post request to the server. url is the link you want to send the request to. params is the data you want to send, for example, "score=5&name=Bob". async should be true. This will return the handle of the request. This will be used to check when the request is ready or if it has can error.
http_check_ready(handle) - This will likely go in the step event, it checks where a request is ready. handle is the handle of the request. This will return true when ready, otherwise false will be returned.
http_check_error(handle) - This checks if the response was an error such as 404 page not found. handle is the handle of the request. This will return true if an error did occur, otherwise false will be returned. Only call this function once you know that the request is ready.
http_retrieve(handle) - Once you know that the request is ready, you can use this function to return the response of the request. If there was an error, the error code will be returned. If there wasn't an error, the response will be returned. handle is the handle of the request. AFTER USING THIS, SET THE HANDLE TO FALSE AS SHOW IN THE EXAMPLE BELOW.

Live Example
http://syntaxgames.c...r/http_request/

Links
http://syntaxgames.c...t_Extension.zip (direct)
http://www.crocko.co...t_Extension.zip (mirror)

Online Documentation
http://syntaxgames.c...umentation.html

Compatibility
I have slightly tested it on IE, Firefox, Opera and Chrome which it all seems to work on. I don't have a mobile device, so I wasn't able to test it on one.

License
Feel free to use and abuse as you wish. Credit appreciated though.

EA Games Developing MMO in HTML5

17 December 2011 - 04:32 AM

http://www.tomshardw...Play,14273.html

The studio will be using HTML5 to bring the game across multiple platforms, eliminating the need to develop native apps for smartphones and tablets. This multi-platform MMO feat has already been accomplished by Spacetime Studios and its two MMOGs, Pocket Legends and Star Legends (although they use native Android and iOS apps), but this will be the first portable, cross-platform MMO strategy title to hit the market.


Pretty cool I reckon.

Success using Game Maker

27 October 2011 - 10:29 AM

27 October 2011
A couple of hours ago, me and the rest of my Young Enterprise Company won $1500 in cash prizes, $1500 for the school as well as $8000 university scholarship money for a business degree at a university.

The Lion Foundation Young Enterprise Scheme or abbreviated as "YES", is an experiential business programme where secondary students set up a company, to create real products or services, and make real profit or loss.

I along side three friends, have setup a Young Enterprise Company and have developed an educational maths computer game, Mathsper the Brainy Ghost as our product using the Game Maker 8.1 software. And what a year it has been.

In Mathsper the Brainy Ghost the player takes on the role of Mathsper, a good ghost who embarks on a great journey to save the world from Spooker, an evil ghost set out to destroy the earth. Mathsper encounters many challenges of addition, subtraction, multiplication and division. The main focus of the game is to encourage children to learn maths in an enjoyable way. The game is being sold $15 NZD per copy.

We weren't able to get a working copy of our game out until last August and haven't had much time to sell it, we have however made tripple figures in sales. We weren't trying to market the product "to the masses" until we received some customer feedback on what they think about the product, and perhaps what could be improved. The feedback was very positive, the kids loved it, however our game does lack some instructions/direction which we plan on working on. The cool thing is that the game has an auto-updater so we can add extra features for all customers to enjoy.

During the year we had to do a number of things for the business including, writting up a business plan, dragons den presentation infront of a panel of judges, going to a trade fair, developing and marketing the product and writting an annual report. We had an awards evening tonight in a pretty fancy hotel, to our delight we won a number of prizes totaling over $10000. But the biggest thing we won was the regional awards. This means that our company are being put on a plane to go to the New Zealand capital to compete for the nationals. This is a very big event and some very high up there people are attending, we have been told that the US Ambassador will probably be attending, the NZ Primeminister might be attending, however this is around election time so he might be quite busy. As well as TV3 in New Zealand.

I'm will try and keep you guys up with this journey, as well as try and give some recognition to YoYo Games for the amazing software.

Here is also a news paper article I found from a while ago: http://www.pressdisp...87-f0f0a047c6eb

17 November 2011
It's been a while since I've given you guys an update on what's been happening.

For the last few weeks we have been busy with school examinations and improving our product. We pumped out a new update of the game about a week ago, which had a couple of bug fixes, news levels, add some cool sounds and a few other thing (it's a lot more work then it sounds!). We then uploaded the latest update (for all our current customers to enjoy), then sent of the new copy to our new suppliers to create more professional packaging, here is the result:

New CD
Posted Image

Later today, our team set up a stall at a local primary school gala (around 100 kids). I had an amazing time, eating candy floss and hanging out with our latest set of little fans. :( sorry to the mum who had a hard time getting her child away from the computer screen after he tried out the game. Throughout the hour we were selling the game, we managed to make $150. Check out some of the photos we took:

Photo 1
Photo 2
Photo 3
Photo 4
Photo 5
That's me on the right in that last photo.

Next stop is the local A & P show tomorrow, which usually attracts a couple of hundred people. Our aim tomorrow is to make at least $1000 (quite optimist, but we'll see how it goes).

I'm proud to be a Game Maker user.

HTTP Communication Extension

26 October 2011 - 11:43 AM

THIS IS INCOMPLETE

I have been asked by a few people how I do my communication stuff for my games. I have decided to take the time to comment, tidy up and improve the code. Sorry that this isn't in a very nice "state" at the moment, but it's early and the morning and I won't be able to work on it for around a week (unless I manage to find time). However maybe this commented code might help someone. As soon as I'm able to work on this, I will update this topic.

I have yet to:
  • Test this code
  • Make an extension for this code
  • Create examples for this code
  • Explain a bit of php mysql
  • Talk about security when using this code
  • Create documentation


Commented Javascript Code
// This array stores all the XMLHttpRequest objects
var http_requests = new Array();

// This array contains all of the handles and response data
// If the request isn't ready, the value will be the number 0
// If the request is ready, the value will be a string 
// containing the response data
var http_handles = new Array();

// First handle starts at 0
var http_next_handle = 0;

/**
 * This function assigns a handle (identification number) for
 * a request
 *
 * @return: The handle for the request
 */
function http_new_handle() {
	// the handle will already have been stored in the variable
	// "http_next_handle". So store it in a temp variable so it 
	// can be returned later on
	var ret = http_handles[http_next_handle];
	
	// sets the handle for the next request
	http_next_handle = http_handles.length;
	
	// returns the handle
	return ret;
}

/**
 * This function frees the handle so it can be used by another
 * request
 *
 * @handle: The identification number for the request that is being
 *			freed
 */
function http_free_handle(handle) {
	// Sets the request to not ready
	http_handles[handle] = false;
	
	// Sets this handle as the next handle to be used for a request
	http_next_handle = handle;
}

/**
 * This function returns weather or not a request is ready
 *
 * @handle: The identification number for the request that is being
 *			checked
 *
 * @return: Returns true if the request with the given handle 
 *			is ready. False is returned if the request isn't ready
 */
function http_check_ready(handle) {
	// Check if the handle data is a boolean (not ready)
	if (typeof(http_handles[handle]) == 'boolean')
		return false;
	return true;
}

/**
 * This function returns weather a request has an error and the
 * code of the error if it has one
 *
 * @handle: The identification number for the request that is being
 *			checked
 *
 * @return: Returns false if there is no error. If there is it
 *          returns the status code for that error (e.g. 404)
 */
function http_check_error(handle) {
	// Check if the handle data is a number (error)
	if (typeof(http_handles[handle]) == 'number')
		return http_handles[handle];
	return false;
}

/**
 * This function returns the request data for a specified handle
 * and frees the handle
 *
 * @handle: The identification number for the request that is being
 *			return
 *
 * @return: Returns the request data for that handle
 */
function http_request_get(handle) {
	// store the request data to be returned later on
	var ret = http_handles[handle];
	
	//free the request
	http_free_handle(handle);
	
	// return the request data
	return ret;
}

/**
 * This is an object containing information about a request
 *
 * @free: Weather the object is free
 * @request: The XMLHTTPRequest object
 * @handle: The handle associated with the request 
 */
function http_request(handle) {
	this.free = true;
	this.request = new XMLHttpRequest();
	this.handle = handle;
}

/**
 * This function handles sending a HTTP request using the 'get' method
 *
 * @url: The url to the request for example (userid.php?username=bob)
 * @async: Weather or not the request should be asynchronized or not
 *
 * @return: Returns the request data if the request is synchronized
 *			Returns the handle to the request if it is asynchronized
 */
function http_get(url,async)  {
	// gets a handle for the request
	handle = http_new_handle();
	
	// check if there is a free XMLHttpRequest that can be used
	// if there is, the position of it will be stored in, pos
	var pos = -1;
	for (var i=0;i<http_requests.length;i++) {
		if (http_requests[i].free) {
			pos = i;
			http_request.handle = handle;
			break;
		}
	}
	
	// if there isn't a free XMLHttpRequest create a new one
	if (!pos) {
		pos = http_requests.length;
		http_requests[pos] = new http_request(handle);
	}

	// request is being used 
	http_requests[pos].free = false;
	
	// free request onreadystatechange
	if (http_requests[pos].request.onreadystatechange != null)
		http_requests[pos].request.onreadystatechange = null;

	// open the request
	http_requests[pos].request.open("GET",url,async);
	
	// set callback if async is true
	if (async) {
		http_requests[pos].request.onreadystatechange = function() {
			http_request_change(pos);
	}}
	
	// send the request
	http_requests[pos].request.send(null);
	
	// handle synchronized request
	if (!async) {
		// check if request is ready
		if (!http_requests[pos].free && http_requests[pos].request.readyState == 4) {
			http_requests[pos].free = true;
			// return request is there are no errors. If there is an error, return ""
			if (http_requests[pos].request.status == 200 || http_requests[pos].request.status == 304) {
				return http_request[pos].request.responseText;
			} else {
				return "";
			}
		}
	} else
		// asynchronized so return the handle
		return handle;
}

/**
 * This function handles sending a HTTP request using the 'post' method
 *
 * @url: The url to the request for example (userid.php)
 * @param: The params/data to be sent for example (username=bob)
 * @async: Weather or not the request should be asynchronized or not
 *
 * @return: Returns the request data if the request is synchronized
 *			Returns the handle to the request if it is asynchronized
 */
function http_post(url,params,async)  {
	// gets a handle for the request
	handle = http_new_handle();
	
	// check if there is a free XMLHttpRequest that can be used
	// if there is, the position of it will be stored in, pos
	var pos = -1;
	for (var i=0;i<http_requests.length;i++) {
		if (http_requests[i].free) {
			pos = i;
			http_request.handle = handle;
			break;
		}
	}
	
	// if there isn't a free XMLHttpRequest create a new one
	if (!pos) {
		pos = http_requests.length;
		http_requests[pos] = new http_request(handle);
	}

	// request is being used 
	http_requests[pos].free = false;
	
	// free request onreadystatechange
	if (http_requests[pos].request.onreadystatechange != null)
		http_requests[pos].request.onreadystatechange = null;

	// open the request
	http_requests[pos].request.open("POST",url,async);
	
	// set callback if async is true
	if (async) {
		http_requests[pos].request.onreadystatechange = function() {
			http_request_change(pos);
	}}
	
	// set header as post data
	http_requests[pos].request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	// send the request
	http_requests[pos].request.send(params);
	
	// handle synchronized request
	if (!async) {
		// check if request is ready
		if (!http_requests[pos].free && http_requests[pos].request.readyState == 4) {
			http_requests[pos].free = true;
			// return request is there are no errors. If there is an error, return ""
			if (http_requests[pos].request.status == 200 || http_requests[pos].request.status == 304) {
				return http_request[pos].request.responseText;
			} else {
				return "";
			}
		}
	} else
		// asynchronized so return the handle
		return handle;
}

/**
 * This function handles changing of request states for asynchronized requests
 *
 * @pos: Position of the http_request object in the http_requests array
 */
function http_request_change(pos) {
	// check if request is ready
	if (!http_requests[pos].free && http_requests[pos].request.readyState == 4) {
		http_requests[pos].free = true;
		// error checking
		if (http_requests[pos].request.status == 200 || http_requests[pos].request.status == 304) {
			// no errors so set the http handles data to the response data
			http_handles[http_request[pos].handle] = http_request[pos].request.responseText;
		} else {
			// an error occured so set the http handles data to the request status
			http_handles[http_request[pos].handle] = http_requests[pos].request.status;
		}
		// free the handle for the request
		http_free_handle(http_request[pos].handle);
	}
}

Minified Javascript Code
function http_request_change(a){if(!http_requests[a].free&&http_requests[a].request.readyState==4){http_requests[a].free=true;if(http_requests[a].request.status==200||http_requests[a].request.status==304){http_handles[http_request[a].handle]=http_request[a].request.responseText}else{http_handles[http_request[a].handle]=http_requests[a].request.status}http_free_handle(http_request[a].handle)}}function http_post(a,b,c){handle=http_new_handle();var d=-1;for(var e=0;e<http_requests.length;e++){if(http_requests[e].free){d=e;http_request.handle=handle;break}}if(!d){d=http_requests.length;http_requests[d]=new http_request(handle)}http_requests[d].free=false;if(http_requests[d].request.onreadystatechange!=null)http_requests[d].request.onreadystatechange=null;http_requests[d].request.open("POST",a,c);if(c){http_requests[d].request.onreadystatechange=function(){http_request_change(d)}}http_requests[d].request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");http_requests[d].request.send(b);if(!c){if(!http_requests[d].free&&http_requests[d].request.readyState==4){http_requests[d].free=true;if(http_requests[d].request.status==200||http_requests[d].request.status==304){return http_request[d].request.responseText}else{return""}}}else return handle}function http_get(a,b){handle=http_new_handle();var c=-1;for(var d=0;d<http_requests.length;d++){if(http_requests[d].free){c=d;http_request.handle=handle;break}}if(!c){c=http_requests.length;http_requests[c]=new http_request(handle)}http_requests[c].free=false;if(http_requests[c].request.onreadystatechange!=null)http_requests[c].request.onreadystatechange=null;http_requests[c].request.open("GET",a,b);if(b){http_requests[c].request.onreadystatechange=function(){http_request_change(c)}}http_requests[c].request.send(null);if(!b){if(!http_requests[c].free&&http_requests[c].request.readyState==4){http_requests[c].free=true;if(http_requests[c].request.status==200||http_requests[c].request.status==304){return http_request[c].request.responseText}else{return""}}}else return handle}function http_request(a){this.free=true;this.request=new XMLHttpRequest;this.handle=a}function http_request_get(a){var b=http_handles[a];http_free_handle(a);return b}function http_check_error(a){if(typeof http_handles[a]=="number")return http_handles[a];return false}function http_check_ready(a){if(typeof http_handles[a]=="boolean")return false;return true}function http_free_handle(a){http_handles[a]=false;http_next_handle=a}function http_new_handle(){var a=http_handles[http_next_handle];http_next_handle=http_handles.length;return a}var http_requests=new Array;var http_handles=new Array;var http_next_handle=0

EDIT: Also if you have any suggestions on how I can improve my code, please do let me know.

Dash 'n Jump (Facebook)

24 October 2011 - 06:52 PM

http://apps.facebook.com/dash_n_jump/

Simple game using Social:GM extension. This example also tracks the highscore.