• Our friends from AlphaCentauri2.info are in need of technical assistance. If you have experience with the LAMP stack and some hours to spare, please help them out and post here.

Need Help With Lua

PolynesiaOP

Chieftain
Joined
Jan 1, 2016
Messages
18
I'm experienced with modding, and am creating a mod to add Antarctica into the game. The mod hasn't been working with other mods (such as the In Game Editor) and also periodically glitches out, making me think there's an issue with my Lua file. Are there any issues with this?
Spoiler :
Code:
local civilizationID = GameInfoTypes["CIVILIZATION_ANTARCTICA"]
local isAntarcticaIngame = isCivilisationActive(civilizationID)

function Antarctica_TourismIntoScience(playerID)
	local player = Players[playerID]
	if (player:IsAlive() and player:GetCivilizationType() == civilizationID) then 
		for city in player:Cities() do
			local tourism = (city:GetBaseTourism())
			if (tourism > 0)
				city:ChangeScience(tourism)
		end
	end
end
if isAntarcticaIngame then
	GameEvents.PlayerDoTurn.Add(Antarctica_TourismIntoScience)
end
 
Most issues with Lua will be recorded in the lua.log file - to enable logging see the first link in my sig
 
Do as whoward suggests and 1st enable logging and then investigate errors being reported to the lua.log file.

If the code you posted is the entirety of your lua-code, I can see at least three fatal errors which would cause the game to (a) reject the entire contents of the file where the error occurs, or, (b) give runtime errors when the code attempts to execute the Antarctica_TourismIntoScience function, or (c) do nothing once the fatal code errors are fixed.

Spoiler hint for c :
Having a "nil" value contained within a variable called Something will give the same result as having "false" contained within that variable for purposes of true/false evaluations within a conditional line such as
Code:
if Something then
 
Not showing up in my logs, even though I have logging enabled. That's why I posted here - usually errors show up in my logs. What are the other fatal errors (that is the entirety of the Lua for that particular function)?
 
He said there were 3... Thanks but I actually fixed that one right after I posted this when I realized I messed up, but the 3rd one is the one that I think is the issue, but I'm not sure what that is.
 
If that didn't show in the lua.log file, there is almost certainly a 4th ... missing an InGameUIAddin entry for the file.

isCivilisationActive(civilizationID)

is an undefined function, and will also be generating an error
 
If you are not seeing errors in the log it is a fair bet that you do not have any "activation" in modbuddy for the lua file. The errors noted by Klisz should have caused a fatal syntax-error to be reported to the lua.log, and if the line
Code:
city:ChangeScience(tourism)
ever was actually executed, you should be getting this error
Code:
[415658.828] Runtime Error: (the lua file's complete file-path would show here):(the line number from within the lua file with the offending code would be shown here): attempt to call method 'ChangeScience' (a nil value)
as I got when I confirmed that there is no such 'City' method:
Code:
[415658.828] Runtime Error: C:\Users\xxx\Documents\My Games\Sid Meier's Civilization 5\MODS\Washingtron Advance From Kills 2 (v 1)\LUA/Washington_Advance_From_Kills.lua:60: attempt to call method 'ChangeScience' (a nil value)

My other point about whether or not the code you quoted was the entire contents of the lua file had to do with this:
Code:
local isAntarcticaIngame = [COLOR="Red"]isCivilisationActive[/COLOR](civilizationID)
  • If that function is not defined anywhere you will get "nil" for variable "isAntarcticaIngame".
  • If variable "isAntarcticaIngame" is given a value of "nil", then this bit of code will always evaluate to "false" in the conditional and the subscription to the PlayerDoTurn event will never be enacted.
    Code:
    if isAntarcticaIngame then
    	GameEvents.PlayerDoTurn.Add(Antarctica_TourismIntoScience)
    end

[edit]yeah, actually, as whoward said...you should be seeing a fatal error so the issue of the variable being "nil" won't come into play because you'll never get that far.
 
The isCivilisationActive() function doesn't exist in your code, so there is nothing to change.

Presumably you borrowed that code from some other mod, so you need to include the function into your own code.
 
I'm asking if I were to just entirely remake the function, trying to turn 100% of Tourism into Science, what would the code look like?
 
You can use City:GetBaseTourism() to get your tourism output of a city.

Then, you could look at the Colonialist Legacies' Australia's LUA and see how they implement unlimited dummy buildings to produce yields that constantly changes (They did it with trade routes to tourism)
 
Here's the build. Also, I'm not sure why, but I removed the tourism into science effect, but I'm confused on the tile improvement, because it shows up in civ select, but not in game. Same for the UU. Just to clarify, I'm helping my friend on this (he's PolynesiaOP), and I tried to help him with it, but I'm not great with this.
 

Attachments

  1. No such yield as YIELD_TOURISM
  2. You are referencing this: ART_DEF_IMPROVEMENT_RESEARCH_STATION. I see nowhere in the mod where you are telling the game what to do with this reference. Nor do you have any art files as part of the mod, so there is nothing for the game to do with this reference.
  3. You have this:
    Code:
    <GameData>
      <Traits>
        <Row>
          <Type>TRAIT_TOURISM_SCIENCE</Type>
          <Description>TXT_KEY_TRAIT_TOURISM_SCIENCE</Description>
          <ShortDescription>TXT_KEY_TRAIT_TOURISM_SCIENCE_SHORT</ShortDescription>
        </Row>	  
      </Traits>
    
    
      <Language_en_US>
        <Row Tag="TXT_KEY_TRAIT_TOURISM_SCIENCE">
          <Text>Antarctica converts 100% of their [ICON_TOURISM] Tourism into [ICON_RESEARCH] Science.</Text>
        </Row>
        <Row Tag="TXT_KEY_TRAIT_TOURISM_SCIENCE_SHORT">
          <Text>Terra Australis</Text>
        </Row>
      </Language_en_US>
    </GameData>
    But all that does is satidfy the requirment for defining a leader-trait and telling the game what text to display in relation to the leader-trait, but it does not otherwise have any actual effect in-game.

    * You originally had a bunch more lines in the leader trait definition, but those were all just re-stating the default values for each column in table <Traits>, so were not actually accomplishing anything other than to make it more difficult to "read" the code.
  4. So far as I can tell you have no "Build" defined for the Research Station, nor no specification anywhere that workers can do a "build" for a Research Station. The spoiler contains the code AW used for a fort improvement in one of his mods:
    Spoiler :
    Code:
    <GameData>
    	<Improvements>
    		<Row>
    			<Type>IMPROVEMENT_AW_URARTU_FORT</Type>
    			<Description>TXT_KEY_IMPROVEMENT_FORT</Description>
    			<Civilopedia>TXT_KEY_CIV5_IMPROVEMENTS_FORT_TEXT</Civilopedia>
    			<ArtDefineTag>ART_DEF_IMPROVEMENT_FORT</ArtDefineTag>
    			<DestroyedWhenPillaged>true</DestroyedWhenPillaged>
    			<BuildableOnResources>true</BuildableOnResources>
    			<DefenseModifier>50</DefenseModifier>
    			<OutsideBorders>true</OutsideBorders>
    			<PortraitIndex>24</PortraitIndex>
    			<SpecificCivRequired>true</SpecificCivRequired>
    			<CivilizationType>CIVILIZATION_AW_URARTU</CivilizationType>
    			<IconAtlas>TERRAIN_ATLAS</IconAtlas>
    		</Row>
    	</Improvements>
    	<Improvement_ValidTerrains>
    		<Row>
    			<ImprovementType>IMPROVEMENT_AW_URARTU_FORT</ImprovementType>
    			<TerrainType>TERRAIN_GRASS</TerrainType>
    		</Row>
    		<Row>
    			<ImprovementType>IMPROVEMENT_AW_URARTU_FORT</ImprovementType>
    			<TerrainType>TERRAIN_PLAINS</TerrainType>
    		</Row>
    		<Row>
    			<ImprovementType>IMPROVEMENT_AW_URARTU_FORT</ImprovementType>
    			<TerrainType>TERRAIN_DESERT</TerrainType>
    		</Row>
    		<Row>
    			<ImprovementType>IMPROVEMENT_AW_URARTU_FORT</ImprovementType>
    			<TerrainType>TERRAIN_TUNDRA</TerrainType>
    		</Row>
    		<Row>
    			<ImprovementType>IMPROVEMENT_AW_URARTU_FORT</ImprovementType>
    			<TerrainType>TERRAIN_SNOW</TerrainType>
    		</Row>
    	</Improvement_ValidTerrains>
    	<Builds>
    		<Row>
    			<Type>BUILD_AW_URARTU_FORT</Type>
    			<PrereqTech>TECH_ENGINEERING</PrereqTech>
    			<Time>400</Time>
    			<ImprovementType>IMPROVEMENT_AW_URARTU_FORT</ImprovementType>
    			<Description>TXT_KEY_BUILD_FORT</Description>
    			<Help>TXT_KEY_BUILD_FORT_HELP</Help>
    			<Recommendation>TXT_KEY_BUILD_FORT_REC</Recommendation>
    			<EntityEvent>ENTITY_EVENT_BUILD</EntityEvent>
    			<HotKey>KB_F</HotKey>
    			<OrderPriority>1</OrderPriority>
    			<CtrlDown>1</CtrlDown>
    			<IconIndex>30</IconIndex>
    			<IconAtlas>UNIT_ACTION_ATLAS</IconAtlas>
    		</Row>
    	</Builds>
    	<BuildFeatures>
    		<Row>
    			<BuildType>BUILD_AW_URARTU_FORT</BuildType>
    			<FeatureType>FEATURE_JUNGLE</FeatureType>
    			<PrereqTech>TECH_BRONZE_WORKING</PrereqTech>
    			<Time>350</Time>
    		</Row>
    		<Row>
    			<BuildType>BUILD_AW_URARTU_FORT</BuildType>
    			<FeatureType>FEATURE_FOREST</FeatureType>
    			<PrereqTech>TECH_MINING</PrereqTech>
    			<Time>200</Time>
    		</Row>
    		<Row>
    			<BuildType>BUILD_AW_URARTU_FORT</BuildType>
    			<FeatureType>FEATURE_MARSH</FeatureType>
    			<PrereqTech>TECH_MASONRY</PrereqTech>
    			<Time>300</Time>
    		</Row>
    	</BuildFeatures>
    	<Unit_Builds>
    		<Row>
    			<UnitType>UNIT_WORKER</UnitType>
    			<BuildType>BUILD_AW_URARTU_FORT</BuildType>
    		</Row>
    	</Unit_Builds>
    </GameData>
  5. The tourism -> science will require lua. The answer on how to create an lua that will translate tourism into science has already been given.
    • The 1st part of that answer involves adding a dummy building to your mod's xml that will give +1 YIELD_SCIENCE for every copy of the building added to a city.
    • The second part would be using part of the code from the op, but instead of using a non-existent lua-method, simply adding as many copies of the dummy building as there is tourism being generated by the city.
    • Assuming you called the dummy building mentioned in "a" BUILDING_X
      Code:
      pCity:SetNumRealBuilding(GameInfoTypes.BUILDING_X, pCity:GetBaseTourism())

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

Also for future reference zip the mod as it exists directly from the game's MODS folder and not from anywhere else. This ensures that what you are posting (and what you are seeing in-game) is what the game is actually getting from the version of the mod that is in the game's MODS menu.
 
Why is the UU not showing up also? I got a Great Scientist instead of a Great Explorer when I played.
 
Would this work?
Spoiler :
Code:
<?xml version="1.0" encoding="utf-8"?>
<GameData>
	<Improvements>
		<Row>
			<Type>IMPROVEMENT_RESEARCH_STATION</Type>
			<Description>TXT_KEY_IMPROVEMENT_RESEARCH_STATION</Description>
			<Civilopedia>TXT_KEY_CIV5_IMPROVEMENTS_RESEARCH_STATION_TEXT</Civilopedia>
			<Help>TXT_KEY_CIV5_IMPROVEMENTS_RESEARCH_STATION_HELP</Help>
			<ArtDefineTag>ART_DEF_IMPROVEMENT_RESEARCH_STATION</ArtDefineTag>
			<WorldSoundscapeAudioScript></WorldSoundscapeAudioScript>
			<ImprovementPillage></ImprovementPillage>
			<ImprovementUpgrade></ImprovementUpgrade>
			<SpecificCivRequired>1</SpecificCivRequired>
			<CivilizationType>CIVILIZATION_ANTARCTICA</CivilizationType>
			<HillsMakesValid>0</HillsMakesValid>
			<FreshWaterMakesValid>0</FreshWaterMakesValid>
			<RiverSideMakesValid>0</RiverSideMakesValid>
			<NoFreshWater>0</NoFreshWater>
			<RequiresFlatlands>0</RequiresFlatlands>
			<RequiresFlatlandsOrFreshWater>0</RequiresFlatlandsOrFreshWater>
			<RequiresFeature>1</RequiresFeature>
			<RequiresImprovement>0</RequiresImprovement>
			<RemovesResource>0</RemovesResource>
			<PromptWhenComplete>0</PromptWhenComplete>
			<Coastal>0</Coastal>
			<Water>0</Water>
			<DestroyedWhenPillaged>1</DestroyedWhenPillaged>
			<DisplacePillager>0</DisplacePillager>
			<BuildableOnResources>1</BuildableOnResources>
			<BarbarianCamp>0</BarbarianCamp>
			<Goody>0</Goody>
			<Permanent>0</Permanent>
			<OutsideBorders>0</OutsideBorders>
			<InAdjacentFriendly>0</InAdjacentFriendly>
			<IgnoreOwnership>0</IgnoreOwnership>
			<OnlyCityStateTerritory>0</OnlyCityStateTerritory>
			<GraphicalOnly>0</GraphicalOnly>
			<CreatedByGreatPerson>0</CreatedByGreatPerson>
			<NoTwoAdjacent>0</NoTwoAdjacent>
			<AdjacentLuxury>0</AdjacentLuxury>
			<AllowsWalkWater>0</AllowsWalkWater>
			<CultureAdjacentSameType>0</CultureAdjacentSameType>
			<TilesPerGoody>0</TilesPerGoody>
			<GoodyRange>0</GoodyRange>
			<FeatureGrowth>0</FeatureGrowth>
			<UpgradeTime>0</UpgradeTime>
			<RiverSideUpgradeMod>0</RiverSideUpgradeMod>
			<CoastalLandUpgradeMod>0</CoastalLandUpgradeMod>
			<HillsUpgradeMod>0</HillsUpgradeMod>
			<FreshWaterUpgradeMod>0</FreshWaterUpgradeMod>
			<DefenseModifier>0</DefenseModifier>
			<NearbyEnemyDamage>0</NearbyEnemyDamage>
			<PillageGold>10</PillageGold>
			<ResourceExtractionMod>0</ResourceExtractionMod>
			<LuxuryCopiesSiphonedFromMinor>0</LuxuryCopiesSiphonedFromMinor>
			<GoldMaintenance>0</GoldMaintenance>
			<CultureBombRadius>0</CultureBombRadius>
			<RequiresXAdjacentLand>-1</RequiresXAdjacentLand>
			<PortraitIndex>1</PortraitIndex>
			<IconAtlas>TERRAIN_IMPROVEMENT_ICON_ATLAS_EXP2</IconAtlas>
		</Row>
	</Improvements>

	<!-- Trait_ImprovementYieldChanges -->
	<!-- Policy_ImprovementYieldChanges -->
	<!-- Policy_ImprovementCultureChanges -->
	<!-- Belief_ImprovementYieldChanges -->
	<!-- Improvement_Flavors -->
	<Improvement_Yields>
		<Row>
			<ImprovementType>IMPROVEMENT_RESEARCH_STATION</ImprovementType>
			<YieldType>YIELD_FOOD</YieldType>
			<Yield>1</Yield>
		</Row>
		<Row>
			<ImprovementType>IMPROVEMENT_RESEARCH_STATION</ImprovementType>
			<YieldType>YIELD_SCIENCE</YieldType>
			<Yield>2</Yield>
		</Row>
	</Improvement_Yields>
	<!-- Improvement_YieldPerEra -->
	<!-- Improvement_AdjacentCityYields -->
	<!-- Improvement_CoastalLandYields -->
	<!-- Improvement_FreshWaterYields -->
	<!-- Improvement_HillsYields -->
	<!-- Improvement_AdjacentMountainYieldChanges -->
	<!-- Improvement_PrereqNatureYields -->
	<!-- Improvement_RiverSideYields -->
	<Improvement_ValidTerrains>
		<Row>
			<ImprovementType>IMPROVEMENT_RESEARCH_STATION</ImprovementType>
			<TerrainType>TERRAIN_SNOW</TerrainType>
		</Row>
	</Improvement_ValidTerrains>
	<!-- Improvement_ValidTerrains -->
	<!-- Improvement_ValidImprovements -->
	<!-- Improvement_ResourceTypes -->
	<!-- Improvement_ResourceType_Yields -->
	<!-- Improvement_RouteYieldChanges -->
	<Improvement_TechYieldChanges>
		<Row>
			<ImprovementType>IMPROVEMENT_RESEARCH_STATION</ImprovementType>
			<TechType>TECH_CHEMISTRY</TechType>
			<YieldType>YIELD_SCIENCE</YieldType>
			<Yield>1</Yield>
		</Row>
		<Row>
			<ImprovementType>IMPROVEMENT_RESEARCH_STATION</ImprovementType>
			<TechType>TECH_SCIENTIFIC_THEORY</TechType>
			<YieldType>YIELD_SCIENCE</YieldType>
			<Yield>1</Yield>
		</Row>
		<Row>
			<ImprovementType>IMPROVEMENT_RESEARCH_STATION</ImprovementType>
			<TechType>TECH_BIOLOGY</TechType>
			<YieldType>YIELD_SCIENCE</YieldType>
			<Yield>1</Yield>
		</Row>
	</Improvement_TechYieldChanges>
	<!-- Improvement_TechNoFreshWaterYieldChanges -->
	<!-- Improvement_TechFreshWaterYieldChanges -->

	<Builds>
		<Row>
			<Type>BUILD_RESEARCH_STATION</Type>
			<PrereqTech>TECH_CHEMISTRY</PrereqTech>
			<Time>600</Time>
			<ImprovementType>IMPROVEMENT_RESEARCH_STATION</ImprovementType>
			<Description>TXT_KEY_BUILD_RESEARCH_STATION</Description>
			<Help>TXT_KEY_BUILD_RESEARCH_STATION_HELP</Help>
			<Recommendation>TXT_KEY_BUILD_FORT_REC</Recommendation>
			<EntityEvent>ENTITY_EVENT_BUILD</EntityEvent>
			<HotKey>KB_F</HotKey>
			<OrderPriority>1</OrderPriority>
			<CtrlDown>1</CtrlDown>
			<IconIndex>30</IconIndex>
			<IconAtlas>UNIT_ACTION_ATLAS</IconAtlas>
		</Row>
	</Builds>
	<BuildFeatures>
	</BuildFeatures>
	<Unit_Builds>
		<Row>
			<UnitType>UNIT_WORKER</UnitType>
			<BuildType>BUILD_RESEARCH_STATION</BuildType>
		</Row>
	</Unit_Builds>
	
	<Language_en_US>
		<Row Tag="TXT_KEY_IMPROVEMENT_RESEARCH_STATION">
			<Text>Research Station</Text>
		</Row>
		<Row Tag="TXT_KEY_CIV5_IMPROVEMENTS_RESEARCH_STATION_TEXT">
			<Text>
				<!-- Add Civilopedia text here -->
			</Text>
		</Row>
		<Row Tag="TXT_KEY_CIV5_IMPROVEMENTS_RESEARCH_STATION_HELP">
			<Text>A Research Station can be built only on Snow.  It gives +1 [ICON_FOOD] Food and +2 [ICON_RESEARCH] Science and the Science amount increases by 1 after researching Chemistry, Scientific Theory, and Biology.</Text>
		</Row>
	</Language_en_US>
</GameData>
 
What we did was change it so that it no longer gives Tourism, but now gives Science, increasing when certain technologies are discovered - just to clarify.
 
Back
Top Bottom