Not seeing Lua print statement in Fire Tuner console

Jimmyh

Prince
Joined
Nov 20, 2001
Messages
452
Location
Sheffield
I've created a test project in ModBuddy, I added a lua file and it contains this code...

Code:
function Listen(...)

	print(unpack({...}))

end

Events.SerialEventUnitCreated.Add(Listen)

ModBuddy built the project without any errors.

When I build a scout unit in my city I'm not seeing any output in FireTuner.

Is there any thing I need to get this working?

Regards.
 
I'm assuming you've set the Lua file in question to InGameUIAddin already. (I assume this because if you know enough about Lua to write that kind of function, you know how to enable Lua.) If not, then that's your problem.

Besides, you can just ask. The first argument of SerialEventUnitCreated is the player's ID, the second argument is the unit's ID (but note that units are only unique within a single player; two separate civs can have units with the same ID). You can easily convert these to the usual structures by something like:
Code:
    mPlayer = Players[iPlayer];
	mUnit = Players[iPlayer]:GetUnitByID(iUnit);
Those are really the only two arguments you ever need. At that point, you just use something like
Code:
	mType = mUnit:GetUnitType();
	mCombat = GameInfo.Units[mType].Combat;
to get the unit's combat rating, or similar lines for other variables.

There are 13 arguments, and I don't know what the other 11 do (since the existing game doesn't seem to use that function in any of the publicly-available assets). Arguments 3, 7, and 8 are tables, 11, 12, and 13 are booleans, and the rest are integers.

Now, note that the function will fire any time the unit's 3D MODEL enters the game. That means when it is created, when it embarks, when it disembarks, when you load a new savegame, and so on. So if you're trying to do something to the unit, like add extra XP for certain unit types, then you have to do a LOT more to ensure the player doesn't abuse it.

For instance, in my mod, the script gives a custom promotion ("Rookie") to newly-created units, that's automatically removed after their first fight. So my OnUnitCreated script checks to see if that promotion is present; if not, the unit must be new and so gets whatever extra benefits I wanted, but if it has it, OR if the unit was created on a previous turn (since the unit's creation turn is stored in its structure), then do nothing.
 
I like to put a simple print("Modname loaded") at the end of my Lua files so that I see a confirmation message in the console/log when the mod loads. If I don't get a confirmation, then I probably messed up something external like setting it to InGameUIAddin (or forgetting to actually enable the mod ;)), but if I do get a confirmation then I probably messed up something within the file.

In terms of SerialEventUnitCreated, these are the listener arguments smellymummy lists in his AIInfoDump utility:
Code:
( playerID, unitID, hexVec, unitType, cultureType, civID, 
primaryColor, secondaryColor, unitFlagIndex, fogState, 
selected, military, notInvisible )
 
Back
Top Bottom