Odofakyodo
Chieftain
- Joined
- Aug 3, 2021
- Messages
- 10
Hello!
In the mod I'm working on I'm having a trouble accomplishing something that seems like it should be fairly straightforward to do, but I'm having some issues with it. In the mod, I have created a new district, let's call it Foo. I have also created a new building, let's call it Bar. I want to set it up so that when a Foo district has finished construction then a Bar building is automatically created in it (sort of like what happens when Babylon constructs its first Campus and then a Library is automatically created). I have added Foo and Bar in the game's databases and I am able to successfully construct both a Foo and a Bar in the game through "normal" gameplay.
The problem I'm running into is that I cannot get a Bar to be automatically built through gameplay scripts. I have added a new gameplay script - MyScript.lua - to the In-Game actions and it appears to be getting executed. However, the script appears to be halting execution in the middle of my function and I do not know why. Here is the entire script file:
When I construct a Foo district in the game, the output in Lua.log ends with
Due to the fact that the city name is not printed out, the function seems to fail on the line
However, it is strange to me that there are no error messages. I've scoured other lua scripts and there are quite a few in both the base game and other mods that use "Cities.GetCityInPlot()", so I'm not sure what is wrong here. I'm a game programmer by trade and recently gotten into modding Civ VI. I have many many years experience with C++, but Lua is new to me, so I don't know if there's something wrong I'm doing with the language, or if there's something missing from my mod setup. I'm hoping someone can offer some insight, or at least give me some tips on debugging the lua script.
Thanks!
In the mod I'm working on I'm having a trouble accomplishing something that seems like it should be fairly straightforward to do, but I'm having some issues with it. In the mod, I have created a new district, let's call it Foo. I have also created a new building, let's call it Bar. I want to set it up so that when a Foo district has finished construction then a Bar building is automatically created in it (sort of like what happens when Babylon constructs its first Campus and then a Library is automatically created). I have added Foo and Bar in the game's databases and I am able to successfully construct both a Foo and a Bar in the game through "normal" gameplay.
The problem I'm running into is that I cannot get a Bar to be automatically built through gameplay scripts. I have added a new gameplay script - MyScript.lua - to the In-Game actions and it appears to be getting executed. However, the script appears to be halting execution in the middle of my function and I do not know why. Here is the entire script file:
Code:
-- ===========================================================================
function OnDistrictConstructed(iPlayer, eDistrictType, iX, iY)
print("OnDistrictConstructed: BEGIN");
print("OnDistrictConstructed: eDistrictType = " .. eDistrictType);
print("OnDistrictConstructed: (".. iX .. "," .. iY .. ")");
-- If this is a Foo District, then immediately construct the Bar Building.
if (eDistrictType == GameInfo.Districts["DISTRICT_FOO"].Index) then
print("OnDistrictConstructed: District is a Foo!");
local pPlot = Map.GetPlot(iX, iY);
print("OnDistrictConstructed: Plot index is " .. pPlot:GetIndex());
local pCity = Cities.GetCityInPlot(iX, iY);
print("OnDistrictConstructed: City is " .. pCity:GetName());
pCity:CreateBuilding(GameInfo.Buildings["BUILDING_BAR"].Index, 100, pPlot:GetIndex());
end
print("OnDistrictConstructed: END");
end
GameEvents.OnDistrictConstructed.Add(OnDistrictConstructed);
When I construct a Foo district in the game, the output in Lua.log ends with
Code:
MyScript: OnDistrictConstructed: BEGIN
MyScript: OnDistrictConstructed: eDistrictType = 36
MyScript: OnDistrictConstructed: (12,15)
MyScript: OnDistrictConstructed: District is a Foo!
MyScript: OnDistrictConstructed: Plot index is 672
Due to the fact that the city name is not printed out, the function seems to fail on the line
Code:
local pCity = Cities.GetCityInPlot(iX, iY);
However, it is strange to me that there are no error messages. I've scoured other lua scripts and there are quite a few in both the base game and other mods that use "Cities.GetCityInPlot()", so I'm not sure what is wrong here. I'm a game programmer by trade and recently gotten into modding Civ VI. I have many many years experience with C++, but Lua is new to me, so I don't know if there's something wrong I'm doing with the language, or if there's something missing from my mod setup. I'm hoping someone can offer some insight, or at least give me some tips on debugging the lua script.
Thanks!