A couple questions

@Prof. Garfield I figured it out, and thought it might be of interest. Or perhaps this is just obvious stuff. But my unit was set to sea domain. This makes sense why it wouldn't load -- but not necessarily why it would load without the killing Hides function. Just thought you should know, in case it may be of interest to others (e.g., a ship laying mines, but needing a supply tanker to do so?).
 
I'm working on using nearbyUnits and/or getTilesInRadius. I know how to use these for cities, but not for units. I'm trying to make it so, if unit X is in the radius of unit Y, the player can keypress to open a menu. Here is some code I wrote. No error coming up, but no effect.

Spoiler :
Code:
local function isInTradingHouseRadius(tile,unit)
if unit.type == unitAliases.TradingHouse then
    for _,nearbyTile in pairs(gen.getTilesInRadius(tile)) do
        if tile.unit and unit.owner == civ.getTribe(1) then
            return true
        end
    end
    return false
end
end

discreteEvents.onKeyPress(function(keyCode)
local unit = civ.getActiveUnit()
    if keyCode == keyboard.two and (unit.type == unitAliases.Paraibo and unit.location == isInTradingHouseRadius) then do
        civ.ui.text("Testing!")
        end
    end
end)
 
Here are a few different ways to write the isInTradingHouseRadius function. Note that in your code, you also have
Code:
unit.location == isInTradingHouseRadius
which will always be false, since it compares a tileObject to a function.

Code:
local gen = require("generalLibrary")
local function isInTradingHouseRadius(unit)
    for _,nearbyTile in pairs(gen.getTilesInRadius(unit.location,2)) do
        if nearbyTile.defender == unit.owner then
            for nearbyUnit in nearbyTile.units do
                if nearbyUnit.type == unitAliases.TradingHouse then
                    return true
                end
            end
        end
    end
    return false
end
local function isInTradingHouseRadius(unit)
    for nearbyUnit in gen.nearbyUnits(unit.location,2,unit.location.z) do
        if nearbyUnit.type == unitAliases.TradingHouse then
            return true
        end
    end
    return false
end
local function isInTradingHouseRadius(unit)
    local tribe = unit.owner
    for otherUnit in civ.iterateUnits() do
        if otherUnit.type == unitAliases.TradingHouse and 
            otherUnit.owner == tribe and
            gen.distance(unit,otherUnit) <= 2 then
            return true
        end
    end
    return false
end

discreteEvents.onKeyPress(function(keyCode)
    local unit = civ.getActiveUnit()
    if keyCode == keyboard.two and unit.type == unitAliases.Paraibo and isInTradingHouseRadius(unit) then do
        civ.ui.text("Testing!")
        end
    end
end)
Let me know if you want an explanation of how these functions work.
 
Top Bottom