lslsnips
This is an old revision of the document!
Create mosecode in LSL
๐ ๏ธ How It Works Listens on public chat (channel 0).
- Converts each character to Morse using a lookup list.
- Outputs Morse code with spaces between letters and slashes between words.
// Morse code mapping
list morseMap = [
"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", "--..",
"0", "-----", "1", ".----", "2", "..---", "3", "...--", "4", "....-",
"5", ".....", "6", "-....", "7", "--...", "8", "---..", "9", "----."
];
// Convert a string to Morse code
string toMorse(string input) {
input = llToUpper(input);
string result = "";
integer i;
for (i = 0; i < llStringLength(input); ++i) {
string ch = llGetSubString(input, i, i);
integer idx = llListFindList(morseMap, [ch]);
if (idx != -1) {
result += llList2String(morseMap, idx + 1) + " ";
} else if (ch == " ") {
result += "/ "; // Slash for space between words
}
}
return result;
}
// Listen for chat and convert to Morse
default {
state_entry() {
llListen(0, "", NULL_KEY, "");
}
listen(integer channel, string name, key id, string message) {
string morse = toMorse(message);
llSay(0, "Morse: " + morse);
}
}
lslsnips.1760873885.txt.gz ยท Last modified: (external edit)

Discussion