UnitY() is nil inside of a Target Detected event

Post bug reports and ask for game support here.

Moderator: MOD_Command

Post Reply
User avatar
NimrodX
Posts: 82
Joined: Sat May 12, 2018 8:34 pm
Contact:

UnitY() is nil inside of a Target Detected event

Post by NimrodX »

I have an event of the "target detected" sort. There is one single "Unit is Detected" trigger.

I need it to fire only when a specific unit detects the target, so I need a Lua condition that uses ScenEdit_UnitY() to get the detecting unit. I have one single Lua condition for this purpose.

So I have this code for the Lua condition:
local by = ScenEdit_UnitY()
return by.unit.guid == 'XiaoZhanMa-GUID'

This was working perfectly fine earlier but at some point, for no apparent reason, 'by' is coming up as either nil or empty string every time it runs.

Shoulnd't ScenEdit_UnitY() get set to the detecting unit for both conditions and actions?
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: UnitY() is nil inside of a Target Detected event

Post by michaelm75au »

Found an edge case. If no sensor 'made' the contact, then UnitY() will fail. Updated to pass back UnitY() even if no sensor table.
Michael
User avatar
NimrodX
Posts: 82
Joined: Sat May 12, 2018 8:34 pm
Contact:

RE: UnitY() is nil inside of a Target Detected event

Post by NimrodX »

Woohoo! Thanks. This will come in handy.

But I am confused as to how a "Unit is Detected" trigger could trigger if no sensor detected the unit?
Dimitris
Posts: 15480
Joined: Sun Jul 31, 2005 10:29 am
Contact:

RE: UnitY() is nil inside of a Target Detected event

Post by Dimitris »

There are cases where a "presumed" contact is generated, for example if you detect a torpedo or a missile breaks off the sea surface in an otherwise empty area then a "possible sub contact" is automatically created.
User avatar
NimrodX
Posts: 82
Joined: Sat May 12, 2018 8:34 pm
Contact:

RE: UnitY() is nil inside of a Target Detected event

Post by NimrodX »

Ok, but in this case there's a "spy" who spots an aircraft with eyeballs/binoculars. The aircraft didn't fire weapons or do anything to imply that an aircraft should be there. Unless I missed something it's just flying around and should either be seen or not seen by eyeballs/binoculars?

I understand what you mean about the implied existence of something that launches a missile for example, and it makes sense to have no sensors for that case since the contact is essentially an intellectual inference based on the idea that missiles/torpedoes can't come from nowhere. But it doesn't seem like it applies to this case where there's just an airplane flying around not releasing weapons?
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: UnitY() is nil inside of a Target Detected event

Post by michaelm75au »

In this case, the sensor was sometimes 'visual' but more often nothing; I was replaying with the new code and about 3 out of 5 times I got the sensor list with the 'visual' in it with nothing the rest of the time.
This may explain why you say sometimes it was working and others not. Not sure why sometimes the event is being triggered, but by the time the condition kicks in, something has cleared the sensor list.
Michael
Post Reply

Return to “Tech Support”