This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
WolfDood's profile picture

Pig latin translator

Started by WolfDood, 13 November 2016 - 04:28 AM
WolfDood #1
Posted 13 November 2016 - 05:28 AM
So many of you will probably know what pig latin is right… If you don't click this link: http://bit.ly/2eta44Q

Basically you enter a word and it translates to pig latin, aka igpay atinlay.

Here is the pastebin link: http://pastebin.com/9hRzPF8Y

And here is the code:

Spoiler

vowels = {
[1] = "a",
[2] = "e",
[3] = "i",
[4] = "o",
[5] = "u",
[6] = "A",
[7] = "E",
[8] = "I",
[9] = "O",
[10] = "U"
}
vEnd = {
[1] = "w",
[2] = "a",
[3] = "y"
}
cEnd = {
[1] = "a",
[2] = "y"
}
vStart = false
write("Type word to be converted... : ")
local text = read()
text = string.lower(text)
local result = {}
local function splitString()
for letter in text:gmatch(".") do
  table.insert(result, letter)
end
end
local function checkWord()
for i = 1, #vowels do
  if result[1] == vowels[i] then
   vStart = true
  else end
end
return vStart
end
local function convertWord()
if vStart == true then -- Starts with a vowel
  for i = 1, #vEnd do
   table.insert(result, #result + 1, vEnd[i])
  end
else -- Does not start with a vowel
  tempC = result[1]
  table.remove(result, 1)
  table.insert(cEnd, 1, tempC)
  for i = 1, #cEnd do
   table.insert(result, #result + 1, cEnd[i])
  end
end
result[1] = string.upper(result[1])
end
local function printConverted()
for i = 1, #result do
  term.write(result[i])
end
print("")
end
local function Initiate()
splitString()
checkWord()
convertWord()
printConverted()
end
Initiate()

I know this is pretty simple but I only just started CC hopefully you will like it.

EDIT: It is currently in BETA so it doesn't convert consonant clusters as in Br or Sw. It also can only convert one word at a time
Edited on 13 November 2016 - 04:35 AM
WolfDood #2
Posted 13 November 2016 - 06:14 AM
I realise I could use concatentation I might implement that into it
Lion4ever #3
Posted 14 November 2016 - 12:38 AM
A useful trick in lua:
local vowels = {u=true,

local vowels = {
a=true,
e=true,
i=true,
o=true,
u=true}
if vowels[ string.lower( result[1] ) ] then
--this is a vowel
end

If you use the vowel as a key, you dont need a for loop.
WolfDood #4
Posted 14 November 2016 - 01:22 AM
A useful trick in lua:
local vowels = {u=true,

local vowels = {
a=true,
e=true,
i=true,
o=true,
u=true}
if vowels[ string.lower( result[1] ) ] then
--this is a vowel
end

If you use the vowel as a key, you dont need a for loop.

Thanks I will try use that in later versions for now I'm working to make it compatible with consonant clusters

EDIT: Wouldn't you need ""'s around the vowels though
Edited on 14 November 2016 - 12:24 AM
Bomb Bloke #5
Posted 14 November 2016 - 10:07 AM
EDIT: Wouldn't you need ""'s around the vowels though

That sounds like a "try-it-and-see" sort of question, but the short answer is no - not the way they're being used there.