Useless log is useless

AW Arcaeca

Deus Vult
Joined
Mar 10, 2013
Messages
2,984
Location
Operation Padlock ground zero
The following code...
Spoiler :
Code:
-- LuaFile
-- Author: AW
-- DateCreated: 6/17/2014 4:55:33 PM
--------------------------------------------------------------
print("Lua File loaded.")
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
	hasReceivedFreeBonuses = false
	if not hasReceivedFreeBonuses then
		pPlayer = Players[iPlayer]
		print("pPlayer identified")
		if (pPlayer:IsEverAlive()) then
			if (pPlayer:IsAlive()) then
				print("pPlayer is alive; are they NEW_CIV_TYPE")
				if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_NEW_CIV) then
					print("pPlayer is alive; commence to add bonuses")
					pPlayer:GetCapitalCity():ChangeFood(15)
					print ('New Civ Type gets Bonus #1!')
					pPlayer:GetCapitalCity():ChangeProduction(10)
					print ('New Civ Type Gets Bonus #2!')
					hasReceivedFreeBonuses = true
				else
					return
				end
			end
		end
	end
end)
...cause the lua.log to spew this out every single turn:
Spoiler :
Code:
[40861.263] TurnProcessing: Hiding TurnProcessing
[40869.843] LuaFile: pPlayer identified
[40869.843] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40869.968] LuaFile: pPlayer identified
[40869.968] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40870.109] LuaFile: pPlayer identified
[40870.109] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40870.218] LuaFile: pPlayer identified
[40870.218] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40870.327] LuaFile: pPlayer identified
[40870.327] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40870.436] LuaFile: pPlayer identified
[40870.436] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40870.655] LuaFile: pPlayer identified
[40870.655] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40870.889] LuaFile: pPlayer identified
[40870.889] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40871.029] LuaFile: pPlayer identified
[40871.029] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40871.154] LuaFile: pPlayer identified
[40871.154] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40871.263] LuaFile: pPlayer identified
[40871.263] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40871.388] LuaFile: pPlayer identified
[40871.388] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40871.513] LuaFile: pPlayer identified
[40871.513] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40871.622] LuaFile: pPlayer identified
[40871.622] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40871.747] LuaFile: pPlayer identified
[40871.747] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40871.871] LuaFile: pPlayer identified
[40871.871] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40871.981] LuaFile: pPlayer identified
[40871.981] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40872.105] LuaFile: pPlayer identified
[40872.105] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40872.215] LuaFile: pPlayer identified
[40872.215] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40872.339] LuaFile: pPlayer identified
[40872.339] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40872.449] LuaFile: pPlayer identified
[40872.449] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40872.573] LuaFile: pPlayer identified
[40872.573] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40872.698] LuaFile: pPlayer identified
[40872.698] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40872.823] LuaFile: pPlayer identified
[40872.823] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40872.948] LuaFile: pPlayer identified
[40872.948] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40873.041] LuaFile: pPlayer identified
[40873.041] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40873.166] LuaFile: pPlayer identified
[40873.166] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40873.260] LuaFile: pPlayer identified
[40873.260] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40873.385] LuaFile: pPlayer identified
[40873.385] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40873.509] LuaFile: pPlayer identified
[40873.509] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40873.603] LuaFile: pPlayer identified
[40873.603] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40873.728] LuaFile: pPlayer identified
[40873.728] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40873.853] LuaFile: pPlayer identified
[40873.853] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40873.977] LuaFile: pPlayer identified
[40873.977] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40874.071] LuaFile: pPlayer identified
[40874.071] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40874.180] LuaFile: pPlayer identified
[40874.180] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40874.305] LuaFile: pPlayer identified
[40874.305] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40874.430] LuaFile: pPlayer identified
[40874.430] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40874.539] LuaFile: pPlayer identified
[40874.539] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40874.664] LuaFile: pPlayer identified
[40874.664] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40874.773] LuaFile: pPlayer identified
[40874.773] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40874.898] LuaFile: pPlayer identified
[40874.898] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40875.007] LuaFile: pPlayer identified
[40875.007] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40875.132] LuaFile: pPlayer identified
[40875.132] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40875.225] LuaFile: pPlayer identified
[40875.225] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40875.350] LuaFile: pPlayer identified
[40875.350] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40875.459] LuaFile: pPlayer identified
[40875.459] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40875.584] LuaFile: pPlayer identified
[40875.584] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40875.709] LuaFile: pPlayer identified
[40875.709] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40875.818] LuaFile: pPlayer identified
[40875.818] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40875.943] LuaFile: pPlayer identified
[40875.943] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40876.068] LuaFile: pPlayer identified
[40876.068] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40876.317] LuaFile: pPlayer identified
[40876.317] LuaFile: pPlayer is alive; are they NEW_CIV_TYPE?
[40876.317] LuaFile: pPlayer is alive; commence to add bonuses
[40876.317] LuaFile: New Civ Type gets bonus #1!
[40876.317] LuaFile: New Civ Type gets bonus #2!
I'm not sure why it feels it necessary to print the same thing some several hundred trillion (not at all exaggerated :p) times - it appears to be checking every single civ every turn. To top it all off, the game proceeds to crash after about 5 turns, and none of the logs yield any clue as to why.

And every turn? I know it's hooked into GameEvents.PlayerDoTurn, but shouldn't that variable "hasReceivedFreeBonuses" make so that the bonus is only set once?

Furthermore, this coding...
Spoiler :
Code:
print("Loading counts!")
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
	pPlayer = Players[iPlayer]
	print("Identiftying iPlayer's cities.")
	for pCity in pPlayer:Cities() do
		if (pCity:IsHasBuilding(GameInfoTypes.BUILDING_UB)) then
			print("City has UB. Proceed.")
			local randomizer = math.random(1, 3)
			-- 1 = faith
			-- 2 = culture
			-- 3 = production
			
			if (randomizer == 1) then
				pPlayer:ChangeFaith(1)
				print("In city " .. pCity:GetName() .. " UB generates 1 faith.")
			elseif (randomizer == 2) then
				pPlayer:ChangeCulture(2)
				print("In city " .. pCity:GetName() .. " UB generates 2 culture.")
			else
				pCity:ChangeProduction(2)
				print("In city " .. pCity:GetName() .. " UB generates 2 production.")
			end
		else
			return
		end
	end
end)
...for heaven knows why seems to make the game crash upon founding your first city. I don't actually know that for certain, but removing it from the load queue gave me that extra 5 more turns before crashing. Again, the logs yield no errors and I have no clue why. All this is supposed to do is provide a randomized yield each turn per city that has the civ's UB.

I'm playtesting with G&K, but I don't recall using any BNW functions...

Finally, upon selecting the newly built UU the game crashes. There nothing special about it; it has all the same stats as a scout and can do nothing special at the moment... database.log reveals no errors in accidental misspelling or anything... no lua attached to the unit. I can't figure it out. But the mod's not ready to go public yet, so if anyone would like to help me debug this, I can PM them the attachment. I'm just wondering if anyone has any ideas about why any of this is occurring.

Besides the incessant crashing, the civ works mostly fine at the moment.

TIA for any help possible,
AW
 
The first code prints each turn for each civ because you have print statements in code that triggers each turn for each civ. hasReceivedFreeBonuses doesn't make the process happen only once because the first thing the function does it set that to false.

As for the second code, the problem is likely that there is no Player:ChangeCulture, it is Player:ChangeJONSCulture. If you want to change production you ideally want to check to see if the city has production queued up and add to production overflow if not.

Also, I think there is something besides math.random that you're "suppose" to use. There is a game.random method that uses the game's random seed.
 
As to why you are getting all these print statements: it is because that is exactly what you have told the lua to do.
Code:
		pPlayer = Players[iPlayer]
		[COLOR="Red"]print("pPlayer identified")[/COLOR]
		if (pPlayer:IsEverAlive()) then
			if (pPlayer:IsAlive()) then
				[COLOR="red"]print("pPlayer is alive; are they NEW_CIV_TYPE")[/COLOR]
				[COLOR="Blue"]if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_NEW_CIV) then [/COLOR]
The red lines are above the evaluation for CIVILIZATION_NEW_CIV (the blue line), so they are going to fire for every player, and print lines in the log.

These lines
Code:
	hasReceivedFreeBonuses = false
	if not hasReceivedFreeBonuses then
don't appear to be functioning the way you actually want. You are forcing hasReceivedFreeBonuses = false for each and every player since the function runs for each and every player including Barbarians and City-States. This means that if not hasReceivedFreeBonuses then is always being evaluated as the "true" condition for executing the then part of the command. So these two lines aren't actually causing any actual "decision-making", they are effectively non-existant.

Not sure about the other troubles. Would have to think about it some more.

[edit] what Machiavelli said, just he said it more elegantly and with less verbiage !
 
Would it be possible to start off the code with those lines
Code:
hasReceivedFreeBonuses = false
if hasReceivedFreeBonuses then
as in, before the event hook which is before the function? I'm not sure if conditions will work outside of functions like that, but the basic idea is that it should make the code fire only once.

Beyond that, yes, removing the print statement did away with the error. :) Now I just need to get rid of all the excess log print statements...

On another note, no one has any idea why the game crashes upon me selecting the civ's unique unit? :( Has that kind of situation never come up before?
 
Would it be possible to start off the code with those lines
Code:
hasReceivedFreeBonuses = false
if hasReceivedFreeBonuses then
as in, before the event hook which is before the function? I'm not sure if conditions will work outside of functions like that, but the basic idea is that it should make the code fire only once.


Doing something like this would kind of work because it will assign the variable hasReceivedFreeBonuses as a global to the lua 'state' where it is located. But this will only get you part-way to where you'd want to be because when the player saves the game and then re-loads that savefile, the whole thing will fire again because the first thing your lua will do (during game re-loading) is re-read hasReceivedFreeBonuses = false, and when the player pushes the NEXT TURN for the first time after re-loading the savefile, your entire function will re-run, re-add the bonuses, and then set hasReceivedFreeBonuses = true for the rest of that play session. This will recurr for every re-load of a saved game:
Code:
 [COLOR="blue"]hasReceivedFreeBonuses = false[/COLOR]
print("Lua File loaded.")
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
	if not hasReceivedFreeBonuses then
		pPlayer = Players[iPlayer]
		print("pPlayer identified")
		if (pPlayer:IsEverAlive()) then
			if (pPlayer:IsAlive()) then
				print("pPlayer is alive; are they NEW_CIV_TYPE")
				if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_NEW_CIV) then
					print("pPlayer is alive; commence to add bonuses")
					pPlayer:GetCapitalCity():ChangeFood(15)
					print ('New Civ Type gets Bonus #1!')
					pPlayer:GetCapitalCity():ChangeProduction(10)
					print ('New Civ Type Gets Bonus #2!')
					[COLOR="Blue"]hasReceivedFreeBonuses = true[/COLOR]
				else
					return
				end
			end
		end
	end
end)
Your solutions are (1) dummy buildings that add the bonus and in and of themselves act as markers for whether the processing has already occured, (2) persist the value of hasReceivedFreeBonuses using SaveUtils or a similar persisting-data method, (3) some method I have missed but someone else may suggest.

* note that I just re-copied the code from your OP and didn't make any real changes in it other than moving the one variable statement out of the function, so the example as I show still has the multiple print-lines issue.
 
Doing something like this would kind of work because it will assign the variable hasReceivedFreeBonuses as a global to the lua 'state' where it is located. But this will only get you part-way to where you'd want to be because when the player saves the game and then re-loads that savefile, the whole thing will fire again because the first thing your lua will do (during game re-loading) is re-read hasReceivedFreeBonuses = false, and when the player pushes the NEXT TURN for the first time after re-loading the savefile, your entire function will re-run, re-add the bonuses, and then set hasReceivedFreeBonuses = true for the rest of that play session. This will recurr for every re-load of a saved game:
Code:
 [COLOR="blue"]hasReceivedFreeBonuses = false[/COLOR]
print("Lua File loaded.")
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
	if not hasReceivedFreeBonuses then
		pPlayer = Players[iPlayer]
		print("pPlayer identified")
		if (pPlayer:IsEverAlive()) then
			if (pPlayer:IsAlive()) then
				print("pPlayer is alive; are they NEW_CIV_TYPE")
				if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_NEW_CIV) then
					print("pPlayer is alive; commence to add bonuses")
					pPlayer:GetCapitalCity():ChangeFood(15)
					print ('New Civ Type gets Bonus #1!')
					pPlayer:GetCapitalCity():ChangeProduction(10)
					print ('New Civ Type Gets Bonus #2!')
					[COLOR="Blue"]hasReceivedFreeBonuses = true[/COLOR]
				else
					return
				end
			end
		end
	end
end)
Your solutions are (1) dummy buildings that add the bonus and in and of themselves act as markers for whether the processing has already occured, (2) persist the value of hasReceivedFreeBonuses using SaveUtils or a similar persisting-data method, (3) some method I have missed but someone else may suggest.

* note that I just re-copied the code from your OP and didn't make any real changes in it other than moving the one variable statement out of the function, so the example as I show still has the multiple print-lines issue.
Tried it and game crashes upon building my first city. :( No errors from the lua.log, only the print statements telling me that my lua has loaded.

Don't know if it matters, but this is the only other lua I'm running:
Code:
print("Free Worker loaded.")
GameEvents.TeamTechResearched.Add(
function(iTeam, iTech)
	for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
		if (Players[iPlayer] ~= nil) then
			pPlayer = Players[iPlayer]
			if (iTeam == pPlayer:GetTeam()) then
				print("iTeam identified")
				if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_NEW_CIV_TYPE) and (iTech == (GameInfoTypes.TECH_TECHNOLOGY)) then
					print("New Civ Type is present and has researched Technologu. Commence to give free worker.")
					pPlayer:InitUnit(GameInfoTypes.UNIT_WORKER, pPlayer:GetCapitalCity():GetX(), pPlayer:GetCapitalCity():GetY())
					print ('New Civ Type gets free worker!')
				end
			else
				return
			end
		end
	end
end)
This seems to working soundly though...
 
I just tested the chunk of code as was shown in post #5. I changed the civ designation to CIVILIZATION_AMERICA but made no other change. Works fine for me. And also works as I suspected, re-loading the saved game caused the bonuses to recurr on the first NEXT TURN after the savedgame re-load. No crashes of any kind, either of the silent lua-fail type or of the CTD type. Problem has got to be somewhere else, or in some difference between what I used and what you are using on your end.

[edit]which of these are you actually using elsewhere in your mod?
Code:
CIVILIZATION_NEW_CIV
CIVILIZATION_NEW_CIV_TYPE
I just noticed that your sample chunks of lua code have two different designations for the desired civilization. Though I would have thought that an incorrect civ designation would merely have caused a silent lua-file failure rather than a true game "crash"
 
I just tested the chunk of code as was shown in post #5. I changed the civ designation to CIVILIZATION_AMERICA but made no other change. Works fine for me. And also works as I suspected, re-loading the saved game caused the bonuses to recurr on the first NEXT TURN after the savedgame re-load. No crashes of any kind, either of the silent lua-fail type or of the CTD type. Problem has got to be somewhere else, or in some difference between what I used and what you are using on your end.

[edit]which of these are you actually using elsewhere in your mod?
Code:
CIVILIZATION_NEW_CIV
CIVILIZATION_NEW_CIV_TYPE
I just noticed that your sample chunks of lua code have two different designations for the desired civilization. Though I would have thought that an incorrect civ designation would merely have caused a silent lua-file failure rather than a true game "crash"
Gah, didn't notice that. Well, in the coding I'm using in my mod - which differs only in the what the print statements print (like the difference between print("Why is my game crashing?") and print("Dang it you !@#$%^& computer! Work correctly!") , I don't think that should really matter) and the name of the civ, which was copied directly from the XML to ensure that it's spelled correctly - there's no differentiation.

I would use j_amie's (hope I spelled that right) XML checker but I just get an error saying "A Java exception has occurred." when I run it. :/

I'm not sure it's what you'd call crashing, but the game freezes up and I have to use Task Manager to close Civ V, along with getting a windows popup saying that Civ 5 has stopped working correctly. That sounds a lot like crashing to me.

I wonder what would happen if temporarily disabled all the lua...

EDIT: Game crashes even with the lua disabled! :run: What could it mean?!? Still no log errors...
 
Top Bottom