Exception thrown due to (shpRemoveDevice ) in <OnInstall>

Freeform discussion about anything related to modding Transcendence.
Post Reply
User avatar
pixelfck
Militia Captain
Militia Captain
Posts: 571
Joined: Tue Aug 11, 2009 8:47 pm
Location: Travelling around in Europe

Hello,

I'm trying to do some modest modding. I want to uninstall a device ('itStarCannon') and replace it by some other device ('itAlternatingStarCannons') when the install event for the 'itStarCannon' fires.

Code: Select all

<OnInstall>
	(block (starCannons)
		(dbgLog "onInstall event triggered")
		(setq starCannons (list))
		; Enumerate all installed weapons
		(objEnumItems gPlayerShip "wI" aWeapon
			(if
				(and
					(eq (itmGetName aWeapon 0) "Katana star cannon")
					(not (itmIsDamaged aWeapon))
					(not (itmIsEnhanced aWeapon))
					(ls (count starCannons) 2)
					)
				(setq starCannons (lnkAppend starCannons aWeapon))
				)
			)
		(dbgLog (cat "starCannons list is " (count starCannons) " elements long"))
		
		(if (eq (count starCannons) 2)
			(block (alternatingStarCannons)
				; Uninstall and remove the two original star cannons
			;	(enum starCannons aStarCannon
			;		(block Nil
			;			(shpRemoveDevice gPlayerShip aStarCannon)
			;			)
			;		)
			;	(objRemoveItem gPlayerShip (itmCreate &itStarCannon; 2))
			
				; Create and install the alternating star cannons
				(setq alternatingStarCannons (itmCreate &itAlternatingStarCannons; 1))
				(objAddItem gPlayerShip alternatingStarCannons)
				(shpInstallDevice gPlayerShip alternatingStarCannons)
				
				(dbgLog "Replaced 2 Katana star cannons by 1 Fire linked star cannons?"))
				)
			)
		)
</OnInstall>
When I uncomment the commented section and install a second Katana star cannon, I get (in the debug.log file):

Code: Select all

Exception in shpInstallDevice; arg = (gPlayerShip (scrGetItem gScreen))
Exception in shpInstallDevice; arg = (gPlayerShip (scrGetItem gScreen)) [(gPlayerShip (scrGetItem gScreen))] ### (shpInstallDevice gPlayerShip (scrGetItem gScreen)) ###
Could somebody explain what I'm doing wrong?
Last edited by pixelfck on Sun Mar 10, 2013 9:42 pm, edited 1 time in total.
Image
Download the Black Market Expansion from Xelerus.de today!
My other mods at xelerus.de
RPC
Fleet Admiral
Fleet Admiral
Posts: 2876
Joined: Thu Feb 03, 2011 5:21 am
Location: Hmm... I'm confused. Anybody have a starmap to the Core?

What version are you running?
Note:
1.1+ uses PrintTo instead of dbglog
This is crucial since the debug lines don't get run at all :/

The below code works with a recoilless cannon (since I don't have an alt starcannon item >.> )

Code: Select all

(block (starCannons)
			  (PrintTo 'log "onInstall event triggered")
			  (setq starCannons (list))
			  ; Enumerate all installed weapons
			  (objEnumItems gPlayerShip "wI" aWeapon
				 (if
					(and
					   (eq (itmGetName aWeapon 0) "Katana star cannon")
					   (not (itmIsDamaged aWeapon))
					   (not (itmIsEnhanced aWeapon))
					   (ls (count starCannons) 2)
					   )
					(setq starCannons (lnkAppend starCannons aWeapon))
					)
				 )
			  (PrintTo 'log (cat "starCannons list is " (count starCannons) " elements long"))
			  
			  (if (eq (count starCannons) 2)
				 (block (alternatingStarCannons)
					; Uninstall and remove the two original star cannons
				    (enum starCannons aStarCannon
				       (block
				          (shpRemoveDevice gPlayerShip aStarCannon)
				          )
				       )
				    (objRemoveItem gPlayerShip (itmCreate &itRecoillessCannon; 2))
				 
					; Create and install the alternating star cannons
					(setq alternatingStarCannons (itmCreate &itRecoillessCannon; 1))
					(objAddItem gPlayerShip alternatingStarCannons)
					(shpInstallDevice gPlayerShip alternatingStarCannons)
					
					(PrintTo 'log "Replaced 2 Katana star cannons by 1 Fire linked star cannons?"))
					)
				 )
Tutorial List on the Wiki and Installing Mods
Get on Discord for mod help and general chat
Image
Image
Der Tod ist der zeitlose Frieden und das leben ist der Krieg
Wir müssen wissen — wir werden wissen!
I don't want any sort of copyright on my Transcendence mods. Feel free to take/modify whatever you want.
User avatar
pixelfck
Militia Captain
Militia Captain
Posts: 571
Joined: Tue Aug 11, 2009 8:47 pm
Location: Travelling around in Europe

Hmm, There was a 'Nil' missing in my posted code, as a result, the exception did not occur :(
Thanks for the answer though!

Anyhow, the following code seems to cleanly reproduce the exception:

Code: Select all

<OnInstall>
	(block Nil
		(PrintTo 'log "onInstall event triggered")
		(objEnumItems gPlayerShip "wI" aWeapon
			(block Nil
				(PrintTo 'log (cat "Found a " (itmGetName aWeapon 0) ", uninstalling it"))
				(shpRemoveDevice gPlayerShip aWeapon)	
				)
			)
		)
</OnInstall>
It looks like the dockscreen install function throws an exception becaused the installed item does no longer exist when the function call returns? Is this behaviour intented? how do I catch exceptions?
Image
Download the Black Market Expansion from Xelerus.de today!
My other mods at xelerus.de
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

I think that the dockscreen install function is giving errors, since the code you just wrote seems fine to me.

However, OnInstall is called after the item is installed, but before bonuses and enhancements are computed. So the installation of your device is not fully completed but you are trying to remove it.

In your code, just add an exception for gItem (the item that is installed and fired the event onInstall)
It might stop getting an error.
Post Reply