<OnUninstalled> is fired without the device being so

Bug reports for the stable versions go here.
Post Reply
schilcote
Militia Captain
Militia Captain
Posts: 726
Joined: Sat Feb 02, 2008 7:22 pm

When a station is destroyed, it appears that <OnUninstalled> is called on its devices, but the game does not consider them to be uninstalled (see below). Running 1.2 Beta 2, o'course.

Proof:

Stick the following:

Code: Select all

		<Events>
			<OnUninstall>
				(objRemoveItem gSource gItem) ;Destroy ourself when removed.
			</OnUninstall>
		</Events>
on a weapon or such, preferablly the dual recoilless the centauri stations start with. Destroy the station. Get error.

Code: Select all

Item d62ba707 OnUninstall [Centauri warlord camp]: Installed items cannot be removed; use (shpRemoveDevice) instead ### (objRemoveItem gSource gItem) ###
EDIT:

Also, this attempted workaround:

Code: Select all

<OnUninstall>
(block Nil
	(if (itmIsInstalled gItem)
		(block Nil
			(shpRemoveDevice gSource gItem) ;Workaround for a bug that happens when destroying stations
			(printTo 'log "Working around station destruction bug.")
			)
		)
	(objRemoveItem gSource gItem) ;Destroy ourself when removed. Perhaps I should just have the weapon delete the virtual ICX instead of the way it is now?
	)
</OnUninstall>
does not prevent the error message.
[schilcote] It doesn't have to be good, it just has to not be "wow is that the only thing you could think of" bad
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

The fact that <OnUninstall> is run from the devices of the station when the station is destroyed, that sounds like a bug.

However, there are currently no functions to install/uninstall devices on stations from code, so the code you showed (objRemoveItem gSource gItem) is invalid, if run on stations. On ships, it should work as expected.
What are you trying to do ?
If you don't want players to find the weapon in the destroyed station, you could do run <OnDestroy> and remove the device from the loot of the station. Or you could use a virtual device, that will never appear in the loot.
schilcote
Militia Captain
Militia Captain
Posts: 726
Joined: Sat Feb 02, 2008 7:22 pm

It's a laser weapon that's also an ICX system. Installing the weapon also installs the (virtual) ICX device, and removing the weapon removes the device. I'll just have it check if the object it's on is destroyed, and if so don't try removing the item that won't show up anyway. :P

Also, I actually just now noticed I'm having similar issues with a ship, so I'll try using the uninstalling workaround there and see if it works. I wish the xelerus docs told you stuff like that (I guess the fact that it's shpRemoveDevice should have tipped me off).

But yeah, the actual bug here is that <OnUninstall> is being fired when the object is destroyed (which may be intentional), yet the game still considers the device to be installed on something.
[schilcote] It doesn't have to be good, it just has to not be "wow is that the only thing you could think of" bad
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

<OnUninstalled> should not be run except through a hook in the function to uninstall devices. It's run before deinstallation is complete, though, as it has to be because it was originally requested to clean up things like overlays on the object it's installed on and therefore needs the installation context. Try setting up a 1 tick timer to destroy the device instead of doing so in the event.
Literally is the new Figuratively
Post Reply