_James

Text to MorseCode Encoder

Feb 20th, 2016
651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. local Dot = .22
  2. local Dash = Dot * 3
  3. local Beep = script.Parent:WaitForChild("Beep")
  4.  
  5. local Characters = {
  6.     ["a"] = {Dot, Dash};
  7.     ["b"] = {Dash, Dot, Dot, Dot};
  8.     ["c"] = {Dash, Dot, Dash, Dot};
  9.     ["d"] = {Dash, Dot, Dot};
  10.     ["e"] = {Dot};
  11.     ["f"] = {Dot, Dot, Dash, Dot};
  12.     ["g"] = {Dash, Dash, Dot};
  13.     ["h"] = {Dot, Dot, Dot, Dot};
  14.     ["i"] = {Dot, Dot};
  15.     ["j"] = {Dot, Dash, Dash, Dash};
  16.     ["k"] = {Dash, Dot, Dash};
  17.     ["l"] = {Dot, Dash, Dot, Dot};
  18.     ["m"] = {Dash, Dash};
  19.     ["n"] = {Dash, Dot};
  20.     ["o"] = {Dash, Dash, Dash};
  21.     ["p"] = {Dot, Dash, Dash, Dot};
  22.     ["q"] = {Dash, Dash, Dot, Dash};
  23.     ["r"] = {Dot, Dash, Dot};
  24.     ["s"] = {Dot, Dot, Dot};
  25.     ["t"] = {Dash};
  26.     ["u"] = {Dot, Dot, Dash};
  27.     ["v"] = {Dot, Dot, Dot, Dash};
  28.     ["w"] = {Dot, Dash, Dash};
  29.     ["x"] = {Dash, Dot, Dot, Dash};
  30.     ["y"] = {Dash, Dot, Dash, Dash};
  31.     ["z"] = {Dash, Dash, Dot, Dot};
  32.     ["."] = {Dot, Dash, Dot, Dash, Dot, Dash};
  33.     [","] = {Dash, Dash, Dot, Dot, Dash, Dash};
  34.     ["?"] = {Dot, Dot, Dash, Dash, Dot, Dot};
  35.     ["/"] = {Dash, Dot, Dot, Dash, Dot};
  36.     ["1"] = {Dot, Dash, Dash, Dash, Dash};
  37.     ["2"] = {Dot, Dot, Dash, Dash, Dash};
  38.     ["3"] = {Dot, Dot, Dot, Dash, Dash};
  39.     ["4"] = {Dot, Dot, Dot, Dot, Dash};
  40.     ["5"] = {Dot, Dot, Dot, Dot, Dot};
  41.     ["6"] = {Dash, Dot, Dot, Dot, Dot};
  42.     ["7"] = {Dash, Dash, Dot, Dot, Dot};
  43.     ["8"] = {Dash, Dash, Dash, Dot, Dot};
  44.     ["9"] = {Dash, Dash, Dash, Dash, Dot};
  45.     ["0"] = {Dash, Dash, Dash, Dash, Dash}
  46. }
  47.  
  48. function Encode(Text)
  49.     for i = 1, #Text do
  50.         local Character = string.match(string.lower(Text), ".", i)
  51.         local Pattern = Characters[Character]
  52.         if Pattern then
  53.             for _,Length in ipairs(Pattern)do
  54.                 Beep.TimePosition = 0.1
  55.                 Beep:Play()
  56.                 wait(Length)
  57.                 Beep:Stop()
  58.                 wait(Dot)
  59.             end
  60.             wait(Dot * 3)
  61.             Beep:Stop()
  62.         elseif Character == " " then
  63.             Beep:Stop()
  64.             wait(Dot * 7)
  65.         end
  66.     end
  67. end
Advertisement
Add Comment
Please, Sign In to add comment