Hexagon Tile System - Array Implementation?

Recently, I’ve been trying to get hired, but sadly, everybody asks if I have a complete game I can showcase. Because the only personal project I’ve actually made is trash, there is no way I’m going to get hired.

So, I’m thinking of making a game based on Civilizations. I would love to tell you all about it, but that’s not what I’m here for.

In Civilizations, you use a hexagon grid to build buildings and move units. I was curious how I could implement such a grid in Roblox. Here is one of the only things I thought of:

Using a giant array of arras to display rows. For example

local tiles = {
    --Tile data, states, and type would go here instead of numbers
    {1, 2, 3)
    {1, 2}
    {1, 2, 3}

Then, the generation code could create tiles using the length of each array inside a dictionary, and generate rows of hexagon meshes using that data.

I was curious if my method could be refined, or a new one would be better.

Thanks!

1 Like

This is the best article I’ve read about this topic. It’s relevant to game programming in general, and wasn’t written specifically with roblox in mind, but it’s still very applicable.

3 Likes

Just curious, is there any specific strategy you are suggesting from that article? I’m just curious.

Ok. Because I didn’t want to make the axial coordinates listed there, I went with the offset coordinates as these are very easy to take a tile from, and I didn’t want a hexagon map anyways. Thanks for the resource!

1 Like

Alternatively, what I did for my game which has really no way of identifying objects (rasterizer) is when they were instanced I would put them in a array and would call them specifically based on important stuff needed to identify, then from there I used OOP to get the rest.

 local vertex = makeVertex.new()
 list["vertex-serial-"..tostring(1).."-local-"tostring(5)] = vertex

For removing them I would simply use garbage collection

for name, _ in pairs(list) do
  if name == "vertex%-serial%-1%-local%-5" then
    name = nil

 end
end
gcinfo()

this basically does what :Destroy() does to instances, if we just did name = nil we could still access the memory address but gcinfo() permanently removes it from the bank iirc.

2 Likes