HyperText GameMaker

HyperText GameMaker

A web-server framework for GameMaker written in pure GML

Usage Guide   Download

Make Webpages in GameMaker

Use re-usable components to build webpages easily

/** An example "view" */
function ViewExample(): HtmxView() constructor {
  // This view will be mounted at /about
  static path = "about";
	
  // Define a bunch of sub-components
  static lines = [
    new Para("Lorem ipsum dolor sit amet"),
    new Para("Consectetur adipiscing elit"),
    new Para("Etiam mi neque"),
  ];
	
  // This will be called to render the view
  static render = function(_context) {
    // Loop over array of components, and render
    return @'
      <h1>Hello world</h1>
      '+ HtmlComponent.render_array(_lines, "", _context)
  }
}
/** An example component that renders a paragraph */
function Para(_text): HtmlComponent() constructor {
	self.text = _text;
	
	static render = function(_context) {
		return $"<p>{self.text}</p>";
	}
}
// Add ViewExample to the server
// The 'path' will be automatically used
SERVER.add_render(ViewExample);

Make API Endpoints in GameMaker

Create REST endpoints for backend services

/** An example GET endpoint /users/{user_id} */
SERVER.add_path("users/{user_id}", function(_context) {
  if (_context.request.method != "GET") {	  
    throw new ExceptionHttpMethodNotAllowed();
  }
  
  var _user_id = _context.request.parameters.user_id;
  var _user = global.users[$ _user_id];
  if (is_undefined(_user)) {
	throw new ExceptionHttpNotFound("User not found");
  }
  
  _context.response.send_json(_user);
}

Make Websocket servers in GameMaker

Create Websocket endpoints for bi-bidirectional communication in browsers

/** An example websocket handler */
function WebsocketChat(): HttpServerWebsocketSessionBase() constructor {
  // All connected chat clients
  static chat_clients = [];
	
  // add myself to chat clients list
  array_push(self.chat_clients, self);
	
  static on_data_buffer = function(_buffer, _is_string) {
    // decode data
    var _text = buffer_read(_buffer, buffer_text);
    var _json = json_parse(_text);

    // broadcast it to all clients
    array_foreach(self.chat_clients, method({message: _json.message}, function(_client) {
	  _client.websocket.send_data_string(data);
    })
  }
	
  static on_close = function(_close_code=undefined, _close_reason=undefined) {
    // remove myself from chat clients list on disconnect
    var _idx = array_get_index(self.chat_clients, self);
    if (_idx != -1) {
	  array_delete(self.chat_clients, _idx, 1);
    }
  }
}

Ready to start using HyperText GameMaker?

Usage Guide   Download