How Would I Achieve This?

Hey there!

So recently I thought up of a puzzle where the player would have to do a set of corresponding tasks in order to unlock something.

If you’re confused, refer to the picture below.
image

Basically, you have to do an order of things in a specific order for it to work, if you don’t, it resets.

Sorry if my message doesn’t seem clear, I’m currently on a time crunch. Thanks to anybody who helps, I really appreciate it.

2 Likes

Use boolvalues and a manager script. On change of any of the boolvalues, check if the other ones are completed in the right way, then unlock the door. Else, don’t unlock the door.

1 Like

Boolvalues, got it, but how would I check if its completed the right way?

1 Like

Use a table. For example, using table.insert() you can have an order like

stepsToComplete = {
    1,
    2,
    3
}

stepsTaken = {}

When one of the boolvalues changes, if the value is true then insert it into the stepsTaken table. Once the stepstaken table reaches 3 numbers inside it, compare it to the stepsToComplete table :slight_smile:

2 Likes

Sorry for bothering you again, but I’m a bit confused. Could you explain it more thoroughly? I’m a bit on the dumber side.

1 Like

2 tables

1 for the steps that should be taken

and the other for the steps that the player took
the first step the player takes insert the number to the second table

1 Like
local tasks = {
	false,
	false,
	false
} --? Add a "false" for each uncompleted task

local function resetTasks()
	for i, v in ipairs(tasks) do
		tasks[i] = false
	end
end

local function isTaskFinished(task: number): boolean
	return tasks[task]
end

local function finishTask(task: number)
	if not isTaskFinished(task - 1) then --? Task before this wasn't finished
		resetTasks()

		return false --? Failed
	end

	tasks[task] = true

	return true --? Succeeded 
end

Something like this should work, I made each thing a function in case you wanted to edit how tasks are counted as finished or how to make them finished or how to reset them.
To use it, just do this:

local isCompleted = finishTask(2)
if not isCompleted then
	--? Tell the user he did it in the wrong order
end
--? The user is doing them in the right order
1 Like

this code is self explanatory

local puzzle = {
     [1] = 1,
     [2] = 3,
     [3] = 2,
}

if puzzle[1] == 1 and puzzle[2] == 2 and puzzle[3] == 3 then -- if valve order is 123
     -- unlock door
elseif -- if valve order is not 123
     -- reset puzzle
     puzzle[1] = 0
     puzzle[2] = 0
     puzzle[3] = 0
     
     -- door does not unlock
end

since the puzzle is 132, the door will not open and the puzzle will reset