Lua peer edit/debug

Galacticat42

Drifting through space, lost
Joined
May 8, 2008
Messages
1,234
Location
CA, USA
Okay, so I made a random name generator in C++ last year and have converted it into lua just previously for extended colonies/planets/star names, etc. I've looked through the function numerous times for any syntax errors and failed to find any whereas Modbuddy says there is and won't tell me where.

Code:
newName = {
	RandomName = function(NameIsFor)
		local length;
		local letter;
		local finalName;
		local addon;
		local temp;
		local name = "";
	
		local greek = {"Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta", "Theta", "Iota", "Omicron", "Sigma", "Upsilon", "Omega"};
	
		length = math.random(3, 8);
		while true do
			name = "";
			local consonant = 0; --int
			local vowel = 0; -- int
			local ttlVowel = 0;
			local _yNum = 0; --int
			local invalid = false;
			local rounds = 0; --int
			local constCluster = 0; --int
			local willRepeat = 0; --int

			while true do
				local letterNum = math.random(26);
				if letterNum < 2 then
					letter = "a";
					consonant = 0;
					vowel = vowel + 1;
					ttlVowel = ttlVowel + 1;
					_yNum = 0;
				elseif letterNum < 3 then
					letter = "b";
					consonant = consonant + 1.7;
					vowel = 0;
					_yNum = 0;
				elseif letterNum < 4 then
					letter = "c";
					consonant = consonant + .7;
					vowel = 0;
					_yNum = 0;
				elseif letterNum < 5 then
					letter = "d";
					consonant = consonant + .7;
					vowel = 0;
					_yNum = 0;
				elseif letterNum < 6 then
					letter = "e";
					consonant = 0;
					vowel = vowel + 1;
					ttlVowel = ttlVowel + 1;
					_yNum = 0;
				elseif letterNum < 7 then
					letter = "f";
					consonant = consonant + 1;
					vowel = 0;
					_yNum = 0;
				elseif letterNum < 8 then
					letter = "g";
					consonant = consonant + .7;
					vowel = 0;
					_yNum = 0;
				elseif letterNum < 9 then
					letter = "h";
					consonant = consonant + .7;
					vowel = 0;
					_yNum = 0;
				elseif letterNum < 10 then
					letter = "i";
					consonant = 0;
					vowel = vowel + 1;
					ttlVowel = ttlVowel + 1;
					_yNum = 0;
				elseif letterNum < 11 then
					letter = "j";
					consonant = consonant + 1.7;
					vowel = 0;
					_yNum = 0;
				elseif letterNum < 12 then
					letter = "k";
					consonant = consonant + 1.7;
					vowel = 0;
					_yNum = 0;
				elseif letterNum < 13 then
					letter = "l";
					consonant = consonant + 1;
					vowel = 0;
					_yNum = 0;
				elseif letterNum < 14 then
					letter = "m";
					consonant = consonant + 1;
					vowel = 0;
					_yNum = 0;
				elseif letterNum < 15 then
					letter = "n";
					consonant = consonant + 1;
					vowel = 0;
					_yNum = 0;
				elseif letterNum < 16 then
					letter = "o";
					consonant = 0;
					vowel = vowel + 1;
					ttlVowel = ttlVowel + 1;
					_yNum = 0;
				elseif letterNum < 17 then
					letter = "p";
					consonant = consonant + 1;
					vowel = 0;
					_yNum = 0;
				elseif letterNum < 18 then
					letter = "q";
					consonant = consonant + 2;
					vowel = 0;
					_yNum = 0;
				elseif letterNum < 19 then
					letter = "r";
					consonant = consonant + .7;
					vowel = 0;
					_yNum = 0;
				elseif letterNum < 20 then
					letter = "s";
					consonant = consonant + 1;
					vowel = 0;
					_yNum = 0;
				elseif letterNum < 21 then
					letter = "t";
					consonant = consonant + 1;
					vowel = 0;
					_yNum = 0;
				elseif letterNum < 22 then
					letter = "u";
					consonant = 0;
					vowel = vowel + 1;
					ttlVowel = ttlVowel + 1;
					_yNum = 0;
				elseif letterNum < 23 then
					letter = "v";
					consonant = consonant + 1.7;
					vowel = 0;
					_yNum = 0;
				elseif letterNum < 24 then
					letter = "w";
					consonant = consonant + 1.7;
					vowel = 0;
					_yNum = 0;
				elseif letterNum < 25 then
					letter = "x";
					consonant = consonant + 2;
					vowel = 0;
					_yNum = 0;
				elseif letterNum < 26 then
					letter = "y";
					consonant = 0;
					vowel = 0;
					_yNum = _yNum + 1;
				elseif letterNum < 27 then
					letter = "z";
					consonant = consonant + 1;
					vowel = 0;
					_yNum = 0;
				end
				if  temp == "q" then
					letter = "u";
				end
				if  letter == temp then
					willRepeat = willRepeat + 1;
				end
				temp = letter;
		
				if  rounds == 0 then
					letter = str:gsub(letter, string.upper);
				end
				name = name + letter;
				rounds = rounds + 1;
		
				if  consonant > constCluster then
					constCluster = consonant;
				end
				if (length == 3)then
					if consonant > 1 || vowel > 1 then
						invalid = true;
					end
				end
				if consonant >= 2 || vowel > 2 || _yNum > 1 || willRepeat > 2 then
					invalid = true;
				end
				if (rounds >= length) then
					break;
				end
			end
			if ttlVowel > length*.3 && constCluster <= 2 && invalid == false then
				break;
			end
		end
		local addonGen;
		local nameAddon = 0;
		if NameIsFor == "Star" then
			addonGen = math.random(12);
			addon = greek[addonGen];
			nameAddon = math.random(2);
		end
		if nameAddon == 0 then
			finalName = name;
		elseif nameAddon == 1 then
			finalName = addon + " " + name;
		elseif nameAddon == 2 then
			finalName = name + " " + addon;
		end
	
		print(finalName);
		return finalName;
	end
}
 
I ran it through the Lua interpreter and it complained about the pipe symbol. Change all the "||" to "or" and the ""&&" to "and".

Thanks, I'll change those... It's always tough to point out syntax errors like that when the two languages are mushed in your brain.

EDIT: that did it, thanks a bunch.
 
Back
Top Bottom