nukkxx5058
Posts: 2932
Joined: 2/3/2005 From: France Status: offline
|
quote:
ORIGINAL: musurca quote:
ocal killer = ScenEdit_UnitY() print(killer.unit.classname) Not sure why but it does work ... In fact this one works too: print(killer.unit). You can do it that way—but I'd recommend first using a conditional to check if killer is valid as I posted in the code above. The reason is that under certain circumstances ScenEdit_UnitY() will return a nil value. If that happens, and if you try to access killer.unit when killer is nil, your code will fail silently at that point. I just had the problem of UnitY() returning a nil value. I can't understand why this is happening. Fortunately, with the IF statement I'm able to bypass this but it's quite weird and I'm obliged to flag the killer's weapon as unknown in the log each time UnitY() return a nil value. Any idea why this is happening ? quote:
07/04/2013 05:02: Score changed from 0 to 100. Reason: France Ship D 644 Primauguet [Type F70] (D 644 Primauguet [Type F70] Subtype: 3203 ) Killed by UK / Weapon: unknown / Points: 100 07/04/2013 05:02: Score changed from 100 to 110. Reason: France Aircraft Hercules #1 (Lynx HAS.4(FN) Subtype: 6001 ) Killed by UK / Weapon: unknown / Points: 10 07/04/2013 05:08: Score changed from 110 to 10. Reason: UK Submarine S 20 Astute (S 119 Astute Subtype: 2010 ) Killed by France / Weapon: MU-90 Impact / Points: -100 And I'm obliged to insert my code in the IF THEN ELSE condition and have to force the weapon to "unknown" when this occurs. quote:
local killer = ScenEdit_UnitY() --killer identification local killer_unit = nil if killer then --check if killer is not nil if killer.unit then killer_unit = killer.unit ScenEdit_SetScore(side, currentScore, sideB.." "..unit.type.." "..unit.name.. " ("..unit.classname.." Subtype: "..unit.subtype.." ) Killed by ".. side .." / Weapon: "..killer_unit.classname.." / Points: "..points) ScenEdit_SetScore(sideB, currentScoreB, sideB.." "..unit.type.." "..unit.name.. " ("..unit.classname.." Subtype: "..unit.subtype.." ) Killed by ".. side .." / Weapon: "..killer_unit.classname.." / Points: " ..-points) end else ScenEdit_SetScore(side, currentScore, sideB.." "..unit.type.." "..unit.name.. " ("..unit.classname.." Subtype: "..unit.subtype.." ) Killed by ".. side .." / Weapon: unknown".." / Points: "..points) ScenEdit_SetScore(sideB, currentScoreB, sideB.." "..unit.type.." "..unit.name.. " ("..unit.classname.." Subtype: "..unit.subtype.." ) Killed by ".. side .." / Weapon: unknown".." / Points: " ..-points) end Would have preferred if UnitY() always returned a value.
< Message edited by nukkxx5058 -- 12/28/2021 7:05:04 PM >
|