Non existant error message

i am completely lost…

so i am currently trying to make the Game Of Life by Conway on roblox but an issue appeared so to fix it i had to create a table of the precedent frame, wich i did but then i realised that the table of the last generation and the table for the current state are syncronised somehow so i searched up on documentation and foudn this function to clone a table containing tables :

image

but when i tested the game to see if it worked i had 0 fps for 10 seconds and then the script just stopped working, so i looked in the ouput but i only found this :

there’s the details about an error message but no actual error message wich is really confusing me

here’s my script :

-- variables

local mainFrame = script.Parent
local controlsFrame = mainFrame.ControlsFrame
local grid = mainFrame.Grid
local generating = false
local running = false
local template = grid.Template:Clone()
local previousPixels = {}
local pixels = {}

-- settings

local gridSize = 50
local aliveColor = Color3.fromRGB(44, 174, 255)
local deadColor = Color3.fromRGB(0, 0, 0)
local oldColor = Color3.fromRGB(25, 99, 145)
local aliveChancePercentage = 10
local aliveAmountRange = {2, 3}
local aliveAmountToReproduce = 3
local tickSpeed = 10

-- functions

function createGrid()
	if not generating then
		generating = true
		table.clear(pixels)
		table.clear(previousPixels)
		for i, v in grid:GetChildren() do
			if v:IsA("TextButton") then
				v:Destroy()
			end
		end

		for x = 1, gridSize do
			for y = 1, gridSize do
				local pix = {
					xpos = x,
					ypos = y,
					alive = false,
					neighbours = {},
					pixel = nil
				}
				if math.random(1, gridSize) <= aliveChancePercentage/100*gridSize then
					pix.alive = true
				end
				pixels[pix.xpos.."/"..pix.ypos] = pix
			end
		end

		for i, pix in pixels do
			local p = template:Clone()
			p.Size = UDim2.new(1/gridSize, 0, 1/gridSize, 0)
			p.Position = UDim2.fromScale(pix.xpos/gridSize, pix.ypos/gridSize)
			if pix.alive then
				p.BackgroundColor3 = aliveColor
			else
				p.BackgroundColor3 = deadColor
			end
			p.Parent = grid

			pix.pixel = p

			local x = pix.xpos
			local y = pix.ypos
			local n = {}

			local neighboursPos = {{x+1, y}, {x-1, y}, {x, y+1}, {x, y-1}, {x+1, y+1}, {x-1, y-1}, {x-1, y+1}, {x+1, y-1}}
			for i, pos in neighboursPos do
				local neighbour = pixels[pos[1].."/"..pos[2]]
				if neighbour then
					table.insert(n, neighbour)
				end
			end
			pix.neighbours = n
		end
		generating = false
	end
	return
end

local function deepCopy(original)
	local copy = {}
	for k, v in pairs(original) do
		if type(v) == "table" then
			v = deepCopy(v)
		end
		copy[k] = v
	end
	return copy
end

function refreshPixels()
	if not generating then
		previousPixels = deepCopy(pixels)

		for i, pix in previousPixels do
			local pix2 = pixels[i]

			local aliveNeighbours = 0
			for i, n in pix.neighbours do
				if n.alive then
					aliveNeighbours += 1
				end
			end

			if pix.alive then
				if aliveNeighbours < 2 or aliveNeighbours > 3 then
					pix2.alive = false
				end
			else
				if aliveNeighbours == 3 then
					pix2.alive = true
				end
			end

			if pix2.alive then
				if pix.alive then
					pix2.pixel.BackgroundColor3 = oldColor
				else
					pix2.pixel.BackgroundColor3 = aliveColor
				end
			else
				pix2.pixel.BackgroundColor3 = deadColor
			end

		end
	end
	
	return
end

-- events

controlsFrame.PlayButton.MouseButton1Click:Connect(function()
	running = true
end)

controlsFrame.PauseButton.MouseButton1Click:Connect(function()
	running = false
end)

controlsFrame.RestartButton.MouseButton1Click:Connect(function()
	local _ = createGrid()
end)

controlsFrame.NextFrameButton.MouseButton1Click:Connect(function()
	local _ = refreshPixels()
end)

-- code

task.wait(1)

local _ = createGrid()

running = true

while task.wait(1/tickSpeed) do
	if not generating and running then
		local _ = refreshPixels()
	end
end

thank you so much for any help :pray::pray::pray::pray:

1 Like

By default, studio will only keep the 5,000 most recent error messages. Anything beyond that is deleted. Try adding a task.wait() in the deepCopy function and running it for only a moment.

3 Likes

I figured it out : the problem was that every element in the table was refering to another element so the table would loop through it self

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.