Paid Beta Begins for My Hero Academia: Battlegrounds!

The thumbnail used for the paid beta release of My Hero Academia: Battlegrounds. From left to right: Tenya, Deku, Ochaco
Thumbnail for MHA: Battlegrounds – left to right: Tenya, Deku, Ochaco

Hello! I’m here to announce the beginning of the paid beta phase for a Roblox game I’ve worked very hard on: My Hero Academia: Battlegrounds!

At the time of writing, this game is in early development and not a full product yet. It’ll be growing month by month: your feedback will help make sure its the best possible game out there! You can unlock, play and level up Deku, Tenya and Ochaco! Make sure you visit the Quest board first. Fight the bots around the school and other players in the yard. Unlock your primary quirk ability at level 10, and then your ultimate at 30. Characters are unlocked from briefcases which are 1,000 coins. Duplicate drops are used to empower already-unlocked characters with more XP! Remember, these numbers are all subject to change, and this is just a small part of the game so far.

I helped create this officially-licensed game while working full-time at Gamefam, who partnered with Crunchyroll and Toho. I’m very happy to see folks try out the game, give their feedback and help us create an even better game. At the time of writing, the game’s Discord server (here’s the invite link) already has over 1,000 members!

Paid Beta Reminders

– Beta means we’re early on in development. You’re seeing this project super early, so this is just a small part of the game we hope to build!
– Keep in mind that this is a paid beta, which means you’ll need to pay some Robux in order for access.
– Additionally, the game is not available in some regions, so please check the game description on Roblox.com beforehand.
– Finally, like all games in early access: be wary of bugs, weird behaviors, or data resets.

In the future, I hope to write more blog posts about this game, its development, and my experience as a programmer at Gamefam. After all, this is a personal blog, not a blog about this game in particular. I’ve always enjoyed being a highly-available cool developer who will answer questions when I can. Which may come as a surprise, given my lack of posts on this site… baby steps, I suppose!

Some additional links:

Your Code Sucks: Improving Your Roblox Lua Coding Habits

You might have picked up one of these terrible coding habits when learning Roblox Lua. Let’s address that, shall we?

Listen… we gotta talk. You’ve got some really bad habits when it comes to scripting on Roblox. You clearly grew a lot since your days as a novice. You’ve been around the block enough times to know when it’s time to move past old habits and grow as a developer. Now’s the time to start improving your Roblox code.

OK, maybe not all of that first paragraph is completely true, but that bit about growing as a developer might interest you a whole ton. In this post, let’s talk about what you can do to clean up your coding habits.

A word of caution: this “advice” (if we’re calling it that) isn’t for the absolute novice. If you’re really-really new, just focus on making things work first and foremost. That’s more important. For the rest of you, let’s get into it!

Continue reading “Your Code Sucks: Improving Your Roblox Lua Coding Habits”

The Binder Pattern

Let’s learn about Binders, a useful pattern that links CollectionService and OOP.

In this post, I’m featuring the Binder pattern, its uses, and reasons you should start using them in your Roblox projects.

A binder connects a CollectionService tag on Instance with an object in Lua code. When a tag is applied to an Instance, an object is constructed from a class with this Instance. During its lifetime, the object might read from various attributes on the instance to modify how it behaves. Finally, if the tag or entire Instance is removed, the object is cleaned up or destroyed accordingly.

For the purposes of this article, I’ll be using this implementation (I recommend you keep this open while reading).

Continue reading “The Binder Pattern”

Shift Lock for Roblox on Mobile Devices

Add support for mouse lock (aka shift lock) for games on Roblox’s mobile app by adding this resource to your game/experience.

I made a handy resource for Roblox developers to support “Mouse Lock” (aka “Shift Lock”) mode in their games for mobile players!

Also consider getting the Model from the Roblox website so it’s available in Studio’s toolbox and on your Roblox account!

Continue reading “Shift Lock for Roblox on Mobile Devices”

Introducing: Modules

The logo for Modules
A fancy logo for Modules I came up with

It’s my pleasure to announce Modules, a simple dependency loader for Roblox!

Modules comes with goodies, too: Event , Maid  and StateMachine  classes just to name a few. These patterns are so commonplace in Roblox development today, they felt right at home to be included.

With Modules, you can require strings instead of ModuleScripts. This greatly simplifies your scripts’ dependencies and streamlines creation of client and server code.

local require = require(game:GetService("ReplicatedStorage"):WaitForChild("Modules"))
local MyModule = require("MyNamespace:MyModule")

Download: Model on Roblox.com, GitHub releases
Links:
Documentation, Repository on GitHub

Continue reading “Introducing: Modules”

Object-Oriented Programming in Lua (Part 5 – Inheritance)

Inheritance is ubiquitous in the world of object-oriented programming. It makes your classes easy-to-maintain and allows you to reuse a lot of your software. In Part 4, we cleaned up some class code and packaged it all into one nice complete class. In this part, we’ll talk about how we can form a relationship between two classes in which a subclass inherits the state and behaviors of a superclass.

Continue reading “Object-Oriented Programming in Lua (Part 5 – Inheritance)”

Graph Theory in Roblox (Part 3 – A Solution)

In the previous article, I described a problem I faced when developing a game with little dudes roaming around a pre-built map. In this article, I’ll outline how I applied graph theory (described in the first article) to solve my problem.

Graphs are about relationships between objects. On my map, there are places that I know a minion can be, and I know which of those places can be accessed from nearby places. I placed parts in Roblox Studio on my map to quickly identify such locations:

Locations on the map that are navigable. Pink nodes represent a path; yellow represents a junction.

Inside each of these Parts, I added ObjectValues whose Values point to adjacent locations in which a minion should be able to travel between. This is essentially building an adjacency list, where each node contains a list of adjacent nodes. This is one of the two main ways to represent a graph in memory; the other method is to store an adjacency matrix of size n-by-n, where n is the number of nodes in a graph. However, I am working with a sparse graph, which means the 100+ nodes only connect to a select few (2-6) other nodes near to them.

Now I have a representation of my map’s network of navigable areas. At runtime, I have the game convert my Parts and ObjectValues into nodes and edges in a graph. The weights of the edges are the euclidean distance between the nodes. If you’d like to view my implementation of graph, node and edge objects, you can download an rbxmx file here. If you’d like to view the source code of each script individually, here are some pastebin links:

The algorithm I selected for shortest path calculation  is the Floyd-Warshall algorithm. For my fellow CS nerds, it runs in order n-cubed time (for every n nodes, we perform n×n×n steps). This algorithm finds all possible paths between all nodes and leaves each node a list of nodes one should travel to if they are to reach a specific destination node. In other words, imagine an n-by-n table, on the left is your current node, on the top is your destination node. It fills out the table with an adjacent node one ought to which one should travel.

Using the results of the Floyd-Warshall algorithm to find the shortest path between two nodes on a graph.

Above is an animation of randomly chosen paths being rendered in sequence. Here is my implementation (also included in the rbxmx file above) as a mix-in for the Graph class:

The result is pretty awesome! Now, all I do is spawn minions at a random node and randomly choose another random node to path towards. And finally here’s a preview of the two minions using the generated paths.

Two minions traversing different paths.

Got questions or comments? Drop me a direct message on Twitter or a message on Roblox.com! I’d love to update this article series with more information.

Graph Theory in Roblox (Part 2 – A Problem)

In the previous article, I went over basic graph theory terms and concepts. Click here to read that article. In this one, I’m going to describe a game design problem I found while working on my project.

First, some background information on my project. Without going into too much detail, it involves two teams roaming a map killing neutral monsters as an objective. One of these neutral monsters I’m calling creeps or minions, similar to those in Defense of the Ancients 2 and League of Legends. In those games, minions align with a team and march  down set paths and assault enemy structures on those paths. However, in my game, minions aren’t on a team, don’t attack structures, and have no set path. Here’s an early draft of the map I’m using:

An early draft of the map (not final). Notice the navigable paths through the map. Click to view the full image.

Minions roam this map freely, and one challenge I’m facing is programming the minion roaming behavior.  I came up with a number of ideas immediately. Here’s some of them:

  • Just walk in some random navigable direction, changing direction if they run into a wall
  • Create a bunch of paths and pick one to follow
  • Pick a random target on the map and use Roblox’s pathfinding to do the hard work for me in finding a path to the point

Well, there’s going to be a lot of minions around this map. Maybe they’ll even travel in packs, who knows! I can’t have the minions raycasting for walls, and I can’t use expensive pathfinding for them to navigate. I also don’t want them switching directions a lot; I’d rather they travel a long path instead of small segments.

How did I apply graph theory to this problem? Find out in the next article.

Graph Theory in Roblox (Part 1 – Intro)

Hey, everyone. Some of you might not know this, but I’m a big nerd when it comes to the topic of computer science. Coding, functions, runtime analysis, space complexity, algorithms… you name a CS topic, I’m probably interested in it. In this series of articles I’m going to outline how I used graph theory, a fundamental topic of computer science, in developing a feature for my current project.

In this article series, I want to give a surface-level introduction to graph theory and showcase the solution to a problem from one of my projects

First and foremost, let’s talk about what graph theory is by defining some of the terms. A graph is a set of vertices (aka nodes), which have edges (aka arcs) connecting them. Two vertices are adjacent if they share an edge. An undirected graph is one in which edges have no direction (edges are lines), and the edges in a directed graph have a direction (edges are arrows). A weighted graph assigns a value to edges

A graph of nodes A through F. Edges: AB, BC, CD, DF, BE, DF
A basic graph with 6 nodes and 6 edges.

Pictured above is a representation of an unweighted, undirected graph featuring nodes labelled A through F. This graph could represent many real-world ideas:

  • A physical map of cities connected by highways
  • A social network of people connected by friendships
  • A set of game board states connected by moves you have to make to get from one state to another
  • A final boss’ attack pattern (nodes are unique attack states, edges are transitions)

Notice how not all of these examples are physical things! They are instead collections of things and relationships between those things. I hope you can start to imagine the many different applications of graphs to real-world problems. Many algorithms have been dreamed up to solve problems involving graphs. To name just a few:

  • Breadth-first (BFS) and depth-first search (DFS) – Two methods of visiting all the nodes in a graph but in different orders
  • Dijkstra’s algorithm – For weighted graphs, find the lowest cost path between two nodes (you cannot use negative edge weights).
  • The Bellman-Ford algorithm – Similar to Dijkstra’s and slower, except you can use negative edge weights (however, there must not be any negative cycles in the graph – a cycle of edges that sum to a negative number)
  • The Floyd-Warshall algorithm – For weighted graphs, calculate all of the paths from each node to every other node.
  • Prim’s algorithm – For weighted graphs, find a minimum spanning tree that visits all nodes, and picks edges so that all nodes are part of the complete graph, while also minimizing costs of used edges.

In the next article, I’ll describe a problem that I identified while working on my project. Later, I show how one of these solve my problem. Click here for part 2 of this series.

Event Systems in Roblox Lua (Part 4 – Full Solution)

Click here for part 3 of this tutorial series, where we used a BindableEvent to take all the work out of creating our own event system. Ok, maybe not all the work, but still…The limitations are real with BindableEvents. Namely the arguments from firing them can’t include special tables, and that’s a problem when we’re working with our custom objects with metatables. Let’s fix it with a little bit of Lua magic.

First off, we need to save the original values when the event is fired. We don’t know what variables are sent to the fire  method, but we are able to save them with a table using the   operator. If you want to know the nitty-gritty, definitely read section 5.2 on variable arguments in Programming in Lua. Let’s add an argument table and an argument count fields in the event itself:

function Event.new()
	local self = setmetatable({
		bindableEvent = Instance.new("BindableEvent");
		argData = nil;
		argCount = nil;
	}, Event)
	return self
end

Note that we don’t have to add these here, by the way. Initializing them to nil does do anything except let us, the programmers, know that these are accessible fields that we’ll use in the future. It’s good practice, so you should get in the habit of showing these fields here.

Next, let’s save the arguments and argument count in these fields by revisiting our fire function:

function Event:fire(...)
	self.argData = {...}
	self.argCount = select("#", ...)
	self.bindableEvent:Fire()
end

Notice how we use   within a table to capture the values into argData . We can now use this table to inspect the possibly many arguments passed. Also, an important detail is the use of the select  function: if you give “#”  as the first argument, it returns the number of arguments passed after it. We just use    again here to do that. Finally, we aren’t even sending anything to the BindableEvent anymore since we’re handling that ourselves. It’s best to remove it for efficiency’s sake.

Okay, now we have all the information saved! How do we use it? We have to get a bit creative with our connect function. Instead of connecting the function directly to the BindableEvent’s Event, we need to connect our own anonymous function. Inside, we’ll unpack  the arguments we saved while firing the event, and use that to call our function.

function Event:connect(func)
	if not func then error("connect(nil)", 2) end
	return self.bindableEvent.Event:connect(function ()
		func(unpack(self.argData, 1, self.argCount))
	end)
end

We use unpack  here in order to return each of the saved arguments from 1 to the number we saved. I’ll save the detailed explanation of unpack for section 5.1 in Programming in Lua. Just know that it’s like returning multiple values from a function, except for unpack  it’s the multiple values are all the indices of the table we give it.

And that should solve our problems with the BindableEvent! We get all the nice threading that Roblox provides internally while working around the table limitations by saving and unpacking them ourselves. Try out the final product with the test code from part 3 and you’ll see the improvement.

And there you have it – just a few ways you can create and use your own custom events within your Lua code on Roblox. You can download the final Event class code here. I had to whittle down my examples to just these 3, so if there’s interest I’ll post others. If you have questions, send me a direct message on Twitter or a message on Roblox. Thanks!