Help! - "'end' expected" error where no 'end' is needed

Killzerslaul

Chieftain
Joined
Nov 4, 2010
Messages
30
Location
Scotland
despite my best efforts, I cannot find a way to stop getting this error which seems to be stopping a function in my mod loading properly.
Code:
Syntax Error: [string "C:\Users\Michael Kellett\Documents\My Games\Sid Meier's Civiliz..."]:61: 'end' expected (to close 'function' at line 9) near 'print'
I have checked my script repeatedly and I don't see any places where an 'end' could be missing.

this is the entire file & function that seems to be causing the issue:
Code:
-- SE_EquipmentFunctions
-- Author: Hashashiyyin
-- DateCreated: 22/7/2012 5:22:00 PM
--------------------------------------------------------------

print( "EquipmentFunctionsIncluded!" )

-- works out the income in equipment type "eEquipment" of player "pPlayer"
function GetEquipment( pPlayer, eEquipment )
	local player = Players[pPlayer]
	local fromBuilding, fromSpecialist, fromTrade, fromResource, fromFood = 0, 0, 0, 0

	print("Getting Equipment Income...")
	local strtext = ""
	strtext = "Getting Equipment Income for Equipment id " .. eEquipment .. " for civ " .. player:GetName() .. "!";
	print(strtext);

	-- direct income from Specialists and Buildings
	if g_EquipmentValues[eEquipment].buildings or g_EquipmentValues[eEquipment].specialists then
		for city in player:Cities() do
			local ratio = 100
			if city:IsResistance() then ratio = 0; end

			-- if there is a table for buildings check for buildings
			if g_EquipmentValues[eEquipment].buildings then
				for k, v in pairs( g_EquipmentValues[eEquipment].buildings ) do
					if city:IsHasBuilding( v.id ) then fromBuilding = fromBuilding + math.ceil( v.bonus * ratio / 100 ); end
				end
			end

			-- if there is a table for specialists check for specialists
			if g_EquipmentValues[eEquipment].specialists then
				for k, v in pairs( g_EquipmentValues[eEquipment].specialists ) do
					fromSpecialist = fromSpecialist + math.ceil( city:GetSpecialistCount( v.id ) * v.bonus * ratio / 100 )
				end
			end
		end
	end

	-- if there is a table for direct resource income, apply the direct resource income
	if g_EquipmentValues[eEquipment].resources then
		for k, v in pairs( g_EquipmentValues[eEquipment].resources ) do
			fromResource = math.ceil( player:GetNumResourceAvailable( v.resource, true ) * v.multiplier )
		end
	end

	-- Direct Income from Food

	if g_EquipmentValues[eEquipment].food then
		fromFood = math.ceil( player:CalculateTotalYield(YieldTypes.YIELD_FOOD) * g_EquipmentValues[eEquipment].food.multiplier )
	end

	-- Trade (to be added)

	--debugging report to livetuner
	local total = fromBuilding + fromSpecialist + fromTrade + fromResource + fromFood
	strtext = "Equipment Income of " .. total .. " calculated! (B" .. fromBuilding .. ", S" .. fromSpecialist .. ", T" .. fromTrade .. ", R" .. fromResource .. ", F" .. fromFood .. " )";
	print( strtext )
	
	return total, fromBuilding, fromSpecialist, fromTrade, fromResource, fromFood
	print( "Completed!" )
	print("-------------------------------------")
end
does anyone know what the problem is? am I missing something important or doing something completely wrong? Is my syntax so awful that your eyes bleed? I'm pretty new to lua and would greatly appreciate help.

thanks. :)

(also, if that code looks familiar, it is because I heavily relied on parts of Gedemon's WW2 mod as a reference. hopefully that's not an issue with anyone, since I'm not actually distributing this mod right now, or claiming it to be entirely original. ^^)
 
You're missing some ; but there are also the two lines with print after the return that I don't think will get executed.
 
the ";" are not mandatory in Lua, but there's 2 lines following the
Code:
return total, fromBuilding, fromSpecialist, fromTrade, fromResource, fromFood
, I think that's may be the problem (return should mark the end of a block)
 
the ";" are not mandatory in Lua, but there's 2 lines following the
Code:
return total, fromBuilding, fromSpecialist, fromTrade, fromResource, fromFood
, I think that's may be the problem (return should mark the end of a block)

ah, right, I didn't know that. thanks. :)

(tested and it works with those 2 lines moved, thanks again!)
 
Back
Top Bottom