Instance no longer exists / Instance does not exist

Perkus

Prince
Joined
Oct 16, 2010
Messages
316
Location
Ontario, Canada
Hi, I'm trying to call a Unit class method called GetAirCombatDamage. It should exist, as it's listed here http://wiki.2kgames.com/civ5/index.php/Lua_Game_Objects/Unit#GetAirCombatDamage, as well as in the Civ5LuaAPI.html. According to the first link, there is one argument, (<Unit> pDefender). Ok, but when I try to call it like this:

iMyDamageInflicted = pMyUnit:GetAirCombatDamage(pTheirUnit);​

I get a Lua.log file message that "Instance does not exist." Calling it with nil

iMyDamageInflicted = pMyUnit:GetAirCombatDamage(nil);​

gives me "Instance no longer exists."

The unit in question is an air unit (pMyUnit:GetDomainType() == DomainTypes.DOMAIN_AIR) , and I'm quite sure the pMyUnit and the pTheirUnit are both valid because it's in the middle of a function that I've been working with and using for days, and otherwise works fine. For example, I can call:

iMyDamageInflicted = pMyUnit:GetRangeCombatDamage(pTheirUnit, nil, false);​

in the same spot, and it works just fine. And yes, I've also tried it with 3 arguments instead.

I also tried printing the attributes on pMyUnit as shown on the wiki:
PHP:
				print("pMyUnit Attributes:")
				for k, v in pairs(getmetatable(pMyUnit).__index) do
					print(k)
				end
				print("End attributes.");

GetAirCombatDamage shows up. But it's in the second section of the list, after an item called just "__instances". Is this relevant?

Can anybody give me any idea why this doesn't work?
 
never used those functions but im guessing that the game forgot what the damage was? maybe thats where this instance thing no long there means.

you can catch damage done in real time though with the combatsimend event:
Spoiler :

Code:
function example(
			atkplayer, atkunitid, atkunitdmg, atkfinalunitdmg, atkmaxhp, 
			defplayer, defunitid, defunitdmg, deffinalunitdmg, defmaxhp
			)

	print ( "attacker\tplayer,unitid,dmg,etc:\t" .. atkplayer, atkunitid, atkunitdmg );
	print ( "defender\tplayer,unitid,dmg,etc:\t" .. defplayer, defunitid, defunitdmg );

end
Events.EndCombatSim.Add( example );
 
Hmm, interesting about that event, that could be useful another time. But I'm calling this pre-combat. It's for forecasting the combat odds of air combat. Similar calls are being made at the same time for ranged and melee combat and work. I don't know why it would be any different for the air version of the function. If I can't get this to run I'll have to spend of whole bunch of extra time trying to simulate the same results through my own code. :sad: I was already resigned to having to do that, but I found that function yesterday and thought it would save me all kinds of effort.
 
ok i see what you mean

the getairdamage i think is there i believe for if/when air units move around like land units. what you want to get is their bombard damage (getrangecombatdamage)

all this time i didnt even realize there's no forecast for air units

edit:
Spoiler :
Code:
> for u in Players[0]:Units() do print ( "0\t", u:GetName(), u:GetID() ); end for u in Players[1]:Units() do print ( "1\t", u:GetName(), u:GetID() ); end
 InGame: 0		Bomber	32768
 InGame: 0		Warrior	16385
 InGame: 1		Warrior	16385
 InGame: 1		Warrior	24578
 InGame: 1		Scout	32771
> print ( Players[0]:GetUnitByID( 32768 ):GetRangeCombatDamage( Players[ 1 ]:GetUnitByID(16385),nil, false ) );
 InGame: 116
 
all this time i didnt even realize there's no forecast for air units

Hence the entire point of me slaving away at this mod! :)

What you have there (GetRangeCombatDamage) actual works for air units, but only in one direction, from the attacker's side. I also want it from the defender's side when it's an interceptor to try & forecast the damage taken from the interception. I was hoping it might work, but I can't get that air function to respond at all. And I figured it was more correct to call GetAir this instead of GetRange if both exist.

Anyhow, thinking about it now, even if the call worked I don't think it would give me the interception damage anyway, it seems likely meant for only working from the attacker's side.
 
Back
Top Bottom