I added a new Happiness level with a mod, but it blocks the City info screen.

pokiehl

Moderator
Moderator
Joined
Mar 5, 2017
Messages
4,115
So I added a new happiness level, Euphoric, when your city gets to +5 amenities. Here's the code.

Code:
INSERT INTO Types (Type, Kind) VALUES ('HAPPINESS_EUPHORIC', 'KIND_HAPPINESS') ;
INSERT INTO Happinesses (HappinessType, Name, MinimumAmenityScore, GrowthModifier, NonFoodYieldModifier, RebellionPoints) VALUES ('HAPPINESS_EUPHORIC', 'LOC_HAPPINESS_EUPHORIC_NAME', '5', '30', '20', '-1') ;
UPDATE Happinesses SET MaximumAmenityScore = '4' WHERE HappinessType = 'HAPPINESS_ECSTATIC' ;

In the code, I also added a maximum amenity for Ecstatic. The code is activated via InGame UpdateDatabase, and there's also a text file.

The issue is, whenever a city gets +5 amenities and achieves Euphoric status, you can no longer look at the city info screen. The bonuses are working, but the city info screen is blocked. Any ideas what might cause this? There are no Database errors logged.
 
Did you ever find a solution? I am working on a mod that adds happiness levels and running into the same issue. I suspect that the issue lies in CityPanel.lua and/or CityPanelOverview.lua since they seem to assume the default happiness levels. Each of these scripts initializes a table as:

local UV_CITIZEN_GROWTH_STATUS :table = {};
UV_CITIZEN_GROWTH_STATUS[0] = {u=0, v=0 }; -- revolt
UV_CITIZEN_GROWTH_STATUS[1] = {u=0, v=0 }; -- unrest
UV_CITIZEN_GROWTH_STATUS[2] = {u=0, v=0}; -- unhappy
UV_CITIZEN_GROWTH_STATUS[3] = {u=0, v=50}; -- displeased
UV_CITIZEN_GROWTH_STATUS[4] = {u=0, v=100}; -- content (normal)
UV_CITIZEN_GROWTH_STATUS[5] = {u=0, v=150}; -- happy
UV_CITIZEN_GROWTH_STATUS[6] = {u=0, v=200}; -- ecstatic


CityPanelOverview.lua references this table as:

Controls.CitizenGrowthStatus:SetTextureOffsetVal( UV_CITIZEN_GROWTH_STATUS[data.Happiness].u, UV_CITIZEN_GROWTH_STATUS[data.Happiness].v );

I haven't worked with lua before, but I think that the possible values for data.Happiness are determined by the Happinesses table in the database where you added the Euphoric happiness level. Euphoric should be index 7 for data.Happiness. I think that when one of your cities reaches Euphoric happiness, CityPanelOverview.lua tries to reference index 7 in UV_CITIZEN_GROWTH_STATUS, which does not exist. I am going to play with this to see if I can fix it.
 
I was able to get the City Details panel to work by editing CityPanel.lua and CityPanelOverview.lua. I have attached an amended version of your Euphoric mod. I would appreciate if someone who has edited lua files in a mod before could take a look at it. I copied and pasted the lua files from the game's Assets folder into my mod and then edited them. I set the mod to have those edited files replace the originals. This was the only way that I could see to do it, but it doesn't feel like this is the way that a mod should make changes to lua files.
 

Attachments

....but it doesn't feel like this is the way that a mod should make changes to lua files.
This is in fact the way mods alter existing UI files.

---------------------------------

As a side note, it is generally better to attach the mod itself rather than the modbuddy project. Unless someone specifically asks to see your modbuddy project it is far easier to look at a completed and executable mod than to have to copy a project for a mod into our modbuddy folders and then build it, and then hope that what you have attached is actually creating the same content as you currently have within the built version of the mod existing in the game's "Mods" folder.
 
I configured the lua file replacing incorrectly when I the modified Euphoric mod earlier. It worked on my machine because I had previously changed the lua files in the game's Assets folder. Use this version instead.
 

Attachments

Back
Top Bottom