MorseBuddy - Your friend for encoding, decoding, and playing back morse code!

Introduction:
Introducing, MorseBuddy! Your friend for encoding, decoding and playing back morse code! This module has many features, such as dialog sound effects in games, or realism oriented games. Morse buddy was just a fun project I did to practice some simple scripting and I thought it could have some use here!

How to use:
This module has multiple useful functions, and more to come. The two main ones are:

Encode(MessageToEncode: string)
Playback(MessageInMorse: table, soundobject: object)

To get a string converted to morse code, you would do

local MorseBuddy = require(game.Workspace.MorseBuddy) --Requires the module

local CoolMessage = MorseBuddy.Encode("hi im super super cool") -- Could be any message you like
print(CoolMessage) -- Prints back the cool message you just converted to morse code!

To playback your super cool message in sound, you would run

local MorseBuddy = require(game.Workspace.MorseBuddy) --Requires the module

local CoolMessage = MorseBuddy.Encode("hi im super super cool") -- Could be any message you like
print(CoolMessage) -- Prints back the cool message you just converted to morse code!

MorseBuddy.Playback(CoolMessage, game.Workspace.MorseCodeSound) --Could be any sound path

You can get MorseBuddy by using this link:
https://www.roblox.com/library/9441166953/Mor-se-Buddy

21 Likes

Great idea. I could see this being quite useful for puzzles/secrets in horror games.

6 Likes

Simple enough for everyone to enjoy. Nice module.

1 Like

mind if you opensource this in github?

--\\   MORSE BUDDY, YOUR FRIEND FOR ENCODING, DECODING, AND PLAYING BACK MORSE CODE!   //--
-- \\   COPYRIGHT 2022 @BowlingKing137 (simplextruealert) ANY UNAUTHORIZED REUPLOADS  //--
--  \\   WILL BE TAKEN DOWN AND SUBJECT TO COPYRIGHT! THANK YOU FOR NOTICING, ENJOY! //--
--   \\   PLEASE NOTE, I HAVEN'T ADDED NUMBERS OR DECODING YET! THIS WILL BE ADDED! //--
local MorseBuddy = {}
--||CONGIG||--
MorseBuddy.BlankWaitTime = 0.75
MorseBuddy.LongWait = 0.75
MorseBuddy.ShortWait = 0.25

--||RUN SCRIPTS, DO NOT EDIT ANYTHING BELOW!||--
MorseBuddy.MorseDictionary = {
	a = {".", "-"},
	b = {"-", ".", ".", "."},
	c = {"-", ".", "-", "."},
	d = {"-", ".", "."},
	e = {"."},
	f = {".", ".", "-", "."},
	g = {"-", "-", "."},
	h = {".", ".", ".", "."},
	i = {".","."},
	j = {".", "-", "-", "-"},
	k = {"-", ".", "-"},
	l = {".", "-", ".", "."},
	m = {"-", "-"},
	n = {"-", "."},
	o = {"-", "-", "-"},
	p = {".", "-", "-", "."},
	q = {"-", "-", ".", "-"},
	r = {".", "-", "."},
	s = {".", ".", "."},
	t = {"-"},
	u = {".", ".", "-"},
	v = {".", ".", ".", "-"},
	w = {".", "-", "-"},
	x = {"-", ".", ".", "-"},
	y = {"-", ".", "-", "-"},
	z = {"-", "-", ".", "."}
}

function MorseBuddy.Encode(MessageToEncode: string)
	local MessageTable = toTable(MessageToEncode)
	local FinishedProduct = {}
	for i,v in pairs(MessageTable) do
		table.insert(FinishedProduct, MorseBuddy.MorseDictionary[v])
	end
	return FinishedProduct
end

function MorseBuddy.Playback(MessageInMorse: table, soundobject: object)
	for i,v in pairs(MessageInMorse) do
		for o,j in pairs(v) do
			if j == "." then
				soundobject:Play()
				task.wait(MorseBuddy.ShortWait)
				soundobject:Stop()
				task.wait(MorseBuddy.ShortWait)
			end
			if j == "-" then
				soundobject:Play()
				task.wait(MorseBuddy.ShortWait)
				soundobject:Stop()
				task.wait(MorseBuddy.LongWait)
			end
			if j ~= "-" and j ~= "." then
				task.wait(MorseBuddy.BlankWaitTime)
			end
		end
		task.wait(MorseBuddy.BlankWaitTime)
	end
end

function toTable(msg: string)
	local NewTable = {}
	local LoweredMessage = string.lower(msg)
	LoweredMessage:gsub(".", function(c) table.insert(NewTable, c) return c end)
	return NewTable
end

return MorseBuddy

that’s the code

4 Likes

so whens decoding gonna release?

1 Like

pretty soon, not too hard to do.

1 Like

I know I’m late but insert this into the module:

 function MorseBuddy.deep_equals(t1, t2)
 	for k1, v1 in pairs(t1) do
 		local v2 = t2[k1]
 		if v2 == nil or v1 ~= v2 then
 			return false
 		end
 	end
 	for k2, v2 in pairs(t2) do
 		local v1 = t1[k2]
 		if v1 == nil or v1 ~= v2 then
 			return false
 		end
 	end
 	return true
 end
 
 function MorseBuddy.Decode(MessageInMorse: table)
 	local FinishedProduct = ""
 	for i,v in pairs(MessageInMorse) do
 		for o,j in pairs(MorseBuddy.MorseDictionary) do
 			if MorseBuddy.deep_equals(v, j) then
 				FinishedProduct = FinishedProduct .. o
 				break
 			end
 		end
 	end
 	return FinishedProduct
 end

Enjoy, if anyone is here anyway.

1 Like

This module is spaghetti code junk from when I was learning to code, I may make a better version using metatables and stuff.

Ok, good luck with it! I’d like to see a vanilla version!

I’m sorry, but I don’t find it rude to put my past self down. I was just stating that this was old work, and not good for my standards now. Though I’d love to hear how you take it as rude

This is correct. I wasn’t referring to melguess’s

Hey! You should try switching your code over to what I have here:
image

long beeps are much more distinguishable this way, awesome resource though :smiley:

This is a cool module! I wonder if there will be a Decode function, will you add that? found out that @commitblue asked for it

I posted one a decode function a while ago :slight_smile:

I think we should update the module and the github page maybe

I’m thinking of writing a remastered one. This is over 2 years old now and my coding capabilities have greatly improved.

1 Like

Nice module! I had to alter the code a bit since the short sound and long sound were indistinguishable, but I will definitely be using this for a puzzle game.

Thing I think you should add:

  • Variables at the top for customization:
    – Configurable wait times for beeps
    – Custom sounds which can be configurable as assetId’s
    – Option to return the sound’s that were created which can be done when calling the Playback
    function or they can just chose where they want to put it at in the variable list
    – More (Depending on what other people want)

  • A decode function