Why is JFD's random function not working?

Uighur_Caesar

Comandante en Jefe
Joined
Mar 14, 2015
Messages
1,227
Location
Florida
So I'm working on a UA that gives flat, open, freshwater tiles a chance to have a free farm upon settling a city. Here's what I currently have:

Spoiler :
Code:
function GetNumAdjacentRivers(playerID, city)
	local numAdjacentRivers = 0
	local plot = Map.GetPlot(city:GetX(), city:GetY())
    for adjacentPlot in PlotAreaSweepIterator(plot, 1, SECTOR_NORTH, DIRECTION_CLOCKWISE, DIRECTION_OUTWARDS, CENTRE_EXCLUDE) do
		local x = adjacentPlot:GetX()
		local y = adjacentPlot:GetY()
		if adjacentPlot:GetOwner() == playerID and adjacentPlot:IsRiver() then
			numAdjacentRivers = numAdjacentRivers + 1
		end
	end

    return numAdjacentRivers    
end

-- JFD_GetRandom
--------------------------------------------------------------------------------------------------------------------------
function JFD_GetRandom(lower, upper)
    return Game.Rand((upper + 1) - lower, "") + lower
end

function IraqRivers(playerID, iX, iY)
	local player = Players[playerID]
	if player:GetCivilizationType() == IraqID and player:IsEverAlive() then
	local plot = Map.GetPlot(iX, iY)
	local city = plot:GetPlotCity()
    for riverPlots in PlotAreaSweepIterator(plot, 2, SECTOR_NORTH, DIRECTION_CLOCKWISE, DIRECTION_OUTWARDS, CENTRE_EXCLUDE) do
		if riverPlots:IsFreshWater() and riverPlots:IsOpenGround() then
		if (riverPlots:GetResourceType() == GameInfoTypes.RESOURCE_WHEAT) then
		riverPlots:SetImprovementType(GameInfoTypes.IMPROVEMENT_FARM, 1)
		else
		if riverPlots:GetResourceType(-1) == -1 then
		if JFD_GetRandom(1,numAdjacentRivers) >= (numAdjacentRivers - 1) then
		riverPlots:SetImprovementType(GameInfoTypes.IMPROVEMENT_FARM, 1)
		end
	end
end
end
end
end
end

if isIraqActive then
GameEvents.PlayerCityFounded.Add(IraqRivers)
end

Everything was working fine until I added the JFD_GetRandom function which results in an error that says "attempt to perform arithmetic on local 'upper' a nil value." That function has always worked for me so I have no idea why it isn't working in this particular case.
 
Back
Top Bottom