Project advice!

https://youtu.be/PIndgGprFA8?si=ggwfggWyrfkErzI3

Hey!

I’m working on a small solo project that’s heavily inspired by H.P. Lovecraft, specifically Lovecraftian Order. (Always was a project I found so interesting)

I’ve finished most of the core systems, but I’m currently struggling with timing and pacing, especially figuring out how long it should take players in total to read through chapters and reach each new stage.

Right now, I have it structured like this, where each group of 10 chapters shares the same time per chapter:

local CHAPTER_TIME_GROUPS = {
{maxChapter = 10, time = 120},
{maxChapter = 20, time = 120},
{maxChapter = 30, time = 250},
{maxChapter = 40, time = 250},
{maxChapter = 50, time = 250},
{maxChapter = 60, time = 350},
{maxChapter = 70, time = 350},
{maxChapter = 80, time = 500},
{maxChapter = 90, time = 500},
{maxChapter = 100, time = 500},
{maxChapter = math.huge, time = 800},
}

With the current setup, the total real-time progression comes out to about 8 hours and 52 minutes.

I don’t want the experience to feel painfully slow, but at the same time I also don’t want it to be too easy or quick to complete.

I’d really appreciate any opinions or advice on the pacing as well as just any other feedback and ideas!

pretty interesting game concept overall. I do recommend numbering your table elements to avoid misorder, easier accessing, and for overall better practice:

local table = {
[1] = {},
[2} = {},
[3] = {},
-- etc
}

How does that change anything besides making it look different when reading it?

When you do local t = {{}, {}, {}} Lua treats that as local t = {[1] = {}, [2] = {}, [3] = {}}.

idk maybe to make sure its sorted just in case. its a better practice.

It’s already sorted in the order that you defined the array. When you make a table without defining the keys, Lua automatically numbers it in the order that you made the table.

its like typechecking. its a bit faster than making the engine take the extra time to number it

Not true. Your way actually produces more bytecode:

Array literal

This is for local t = {"A", "B", "C", "D", "E", "F"}:

Explicit keys

This is for local t = {[1] = "A", [2] = "B", [3] = "C", [4] = "D", [5] = "E", [6] = "F"}:

One SETLIST operation versus 6 SETTABLEN operations. Which option is faster?

Nowhere does it say in either the Lua or Roblox documentation that explicitly defining the keys is faster. Either way, the difference is microscopic and not nearly big enough to be noticed during gameplay.

This is how long both ways take after 5 million table creations:

Benchmark code so you can test it yourself
task.wait(5) -- wait for game to load to make sure that doesn't interfere

-- this is 5 million iterations, realistically you only make a few tables in one go
local ITERATIONS = 5e6 

local function benchmarkArrayLiteral()
	local t0 = os.clock()
	for i = 1, ITERATIONS do
		local t = {"A", "B", "C", "D", "E", "F"}
	end
	return os.clock() - t0
end

local function benchmarkExplicitKeys()
	local t0 = os.clock()
	for i = 1, ITERATIONS do
		local t = {[1] = "A", [2] = "B", [3] = "C", [4] = "D", [5] = "E", [6] = "F"}
	end
	return os.clock() - t0
end

benchmarkArrayLiteral()
benchmarkExplicitKeys()

local t1 = benchmarkArrayLiteral()
local t2 = benchmarkExplicitKeys()

print("Array literal ({{},{}}):", t1)
print("Explicit keys ({[1]=...}):", t2)
print("Ratio (explicit / literal):", t2 / t1)

Test 1:

Test 2:

Test 3:

Test 4:


Test 5:

This is proof that explicitly typing the keys is slower than just doing local t = {'a', 'b', 'c'}

1 Like