• We are currently performing site maintenance, parts of civfanatics are currently offline, but will come back online in the coming days (this includes any time you see the message "account suspended"). For more updates please see here.

Lua script not working

Offisir

Chieftain
Joined
Jan 24, 2014
Messages
7
I've been trying to get this quick Lua script to work, but I'm having trouble. It doesn't do anything, so I commented out everything except for the print function. The Lua.log doesn't reveal anything, no errors and no "does this work" message.

Code:
-- Support
-- Author: Offisir
-- DateCreated: 2/11/2014 11:39:16 AM
--------------------------------------------------------------

print( "does this work?" )

function Support( unit )

	local baseStrength = unit:GetBaseCombatStrength();
	
	if ( unit:GetUnitType() == GameInfoTypes[ "UNIT_ARMY" ] ) then
		
		if ( unit:IsFriendlyUnitAdjacent) then

			unit:SetBaseCombatStrength( baseStrength + 100 );
		end
		else return end
	end
end

"UNIT_ARMY" is the Type for a custom unit I made.
 
If you're just trying to give a unit a strength bonus when it has an adjacent friendly unit, there is a much easier (XML only) way to do it.

Give the unit a promotion that has AdjacentMod = 100 (for a 100% bonus).

As for why this code isn't "working", there are a couple of issues. Since you aren't seeing the "does this work" line being printed it implies that you don't have logging enabled or you did not add the lua file to your mod.

Even after you get this code added to your mod it still won't do anything other than print "does this work" because your Support function is not tied to any event and won't execute.
 
If you're just trying to give a unit a strength bonus when it has an adjacent friendly unit, there is a much easier (XML only) way to do it.

Give the unit a promotion that has AdjacentMod = 100 (for a 100% bonus).

As for why this code isn't "working", there are a couple of issues. Since you aren't seeing the "does this work" line being printed it implies that you don't have logging enabled or you did not add the lua file to your mod.

Even after you get this code added to your mod it still won't do anything other than print "does this work" because your Support function is not tied to any event and won't execute.

Thanks for your answer. I didn't use the XML function because the unit's combat strength is 0, so it wouldn't work. I made sure to enable logging, unless Lua logging and database logging is separate.

Question though, do you have to add Lua files through mod properties, like XML files?
 
Yes, though in the "Content" tab, rather than "Actions."

Thanks, but I'm still a bit confused. I'm not sure what to put it as (MapScript?) since it isn't a UI file and whether importing to VFS is needed.
 
Set lua as UIAddin. VFS should only be true if it is replacing an existing lua file (which it is not in your specific case).
 
Thanks, I finally got the message through to the log. I'll work on fixing the script now :)
 
Back
Top Bottom