How to make a door that has a password and a guide that says the numbers one by one WITH MORSE CODE

How to make a door that has a password and a guide that says the numbers one by one:

After searching the deepest places on the forum I found what I wanted to know … But … I still want to know how to connect a morse code with the correct numbers to open the door. In this case I want to know how to replace the indication of the numbers next to the door with Morse code. Please give me a little help on how to do it.

Make a table with the Morse codes as strings then use the table[number] to retrieve the right Morse text to display.
image

2 Likes

Ummm… Ok… But I want the correct number to be different whenever someone reconnects the game.

I want to somehow connect the correct numbers to open the door to the morse code, and whenever someone disconnects and enters the code again, it changes.

Also, make an intvalue in replicatedstorage

local val = game.ReplicatedStorage.IntValue.Value
local rand = math.random(1000,9999)
val = rand
if val == rand then
local counter = 1
local num = string.sub(""..val.."",counter,counter)
repeat
print(num)
counter +=1
until
counter == 4
end
end

This will check for every number in the int value. Then you can do anything you want to it.

My suggestion would be to make a dictionary table referencing a number with it’s morse translation. Then when you randomize the code, have the script iterate through the new code and get the translations for each number using the table.

For example,
code = 512
Morse = “—.–…-…”

EDIT:
Here’s a quick example I put together. It’s probably not perfect, I wrote it really quickly in studio.

local morseTable = {
    [1] = ".----";
    [2] = '..---';
    [3] = "...--";
    [4] = "....-";
    [5] = ".....";
    [6] = "-....";
    [7] = "--...";
    [8] = "---..";
    [9] = "----.";
    [0] = "-----";
}

local code = math.random(1000,9999)
print(code)

local codeString = tostring(code)

for i=1, #codeString, 1 do
    local a = tonumber(codeString:sub(i,i))
    local morseTranslation = morseTable[a]
    print(morseTranslation)
end

This will output the Morse code in a string, but you could do whatever you wanted with this method.

1 Like

The easiest way in my opinion would be to ignore the proposed Morse tables all together! If you look at Morse code for numbers, you can see a pattern. The lines creep in from to right, with 5 dashes, and turn into dots in the middle, then return to dashes coming in from the left side. For example: “.----” is 1, see how there is 1 dot added? Now there is an aglorithm you can come up with that subtracts 5 and converts the numbers, but that’s more complicated than it has to be. Tables are also more complicated than they have to be. Here is what I came up with.
I believe I commented it fairly well, but feel free to ask if you have any questions.

-- Declare a morse string with all the possible combinations.
local morseString = '----.....-----'

-- Add a function to return individual numbers in morse.
local function numberToMorse(index)
	-- Since morse numbers go backwards, and we can't have a negative place in string, subtract the number of morse string to start from the back.
	return string.sub(morseString, 10 - index, 14 - index)
end

-- Function that converts whole code to morse.
local function codeToMorse(code)
	local morseString = '' -- Empty string to add onto.
	for i = 1, #code do
		morseString = morseString .. ' ' .. numberToMorse(string.sub(code, i, i)) --Concatenates new morse onto string with a space seperator.
	end
	-- Returns finished morse when running is done.
	return morseString
end

--Code creation
--Create a new random number generator with default seed.
local randomGenerator = Random.new()

-- Create a new code and format it to have four zeros, starting at 0.
local code = string.format('%0.4i',tostring(randomGenerator:NextInteger(0, 9999)))

--Use the code to morse to get the Morse code.
local morse = codeToMorse(code)

-- Print the code in number and morse form.
print(code)
print(morse)
2 Likes

Hi! I understood what you meant. I also suppose that I have to put it anywhere (on the morse code flashlight or on the door) Am I right?

Nice, this is a much better example.

Using a Morse table in my opinion is an easier concept to understand than using an algorithm, but if I were to do it, I would definitely do it your way.

1 Like

I’m not entirely sure of what you mean, but as long as you use the code for the door code, and display the morse in some way, it will work.

I definitely agree that it’s a complicated example. That is my bad as I should’ve realized that the table would be a lot easier, but I noticed that you already made one, so I thought there was no point in reinventing the wheel, since yours was perfect for the table method. The algorithm was also hopefully for someone later down the line who is looking for a good way to do it as well. Your example should probably be used by them though, because as you stated, it’s a whole lot easier to understand.

1 Like

Alright! I’ll test it today. If it works correctly (I’m pretty sure it will work) I’ll finish this topic.

Btw, I was talking about where I could put the script.