rpgSelectorInitialItem help please

Freeform discussion about anything related to modding Transcendence.
Post Reply
relanat
Militia Captain
Militia Captain
Posts: 600
Joined: Tue Nov 05, 2013 9:56 am

Wed May 30, 2018 2:15 am

Another initialItem query.

In the next version of the Taipan GodShip there will be an action to "Get Ammo" from the Ship Dock Services Weapons screen, dsD789GodWeaponsDockscreen . It only shows if the cursor is placed on a weapon which uses ammo. On selecting this action we navigate to another dockscreen, dsD789GodGetItemsDockscreen, which shows a list of ammo which is fired by the selected weapon. You can then add ammo as desired.

(The code for both these screens is attached below as 'DockscreenCode NOT A MOD.xml')

The action works fine but on returning to the Weapons screen the cursor is always on the default slot '0' not the weapon which was selected.
The initial item code in the Weapons screen uses rpgSelectorInitialItem (the screen is a modified copy of the standard dock services weaponsSelector screen, dsRPGManageWeapons).

Here is rpgSelectorInitialItem from RPGCode.xml.

Code: Select all

	(setq rpgSelectorInitialItem (lambda (criteria)
                (block (
                
		    ;	deviceSelected is a struct with one of the following fields:
		    ;		slotPosIndex: This means we should select a slot of 
		    ;			this index.
		    ;		installPos: This means we should select a device in this
		    ;			install position.
		    ;		installCategory: This means we should select a device 
		    ;			with this category (or an empty slot with this
		    ;			category).
		    ;		oldSlots: This means that we select the item that was
		    ;			most recently installed (and thus is NOT on this list
		    ;			of old devices).

		    (deviceSelected (scrGetData gScreen 'deviceSelected))

		    ;	If none of the player's devices are installed in one of the
		    ;	oldSlots, then it means that we cancelled installation/upgrade
				
		    (cancelled 
			    (and (@ deviceSelected 'oldSlots)
				    (not (filter (objGetItems gPlayerShip criteria) theItem
					    (not (find (@ deviceSelected 'oldSlots) (itmGetInstallPos theItem)))
					    ))
				    )
			    )
		    )

		   (switch
			    (not deviceSelected)
				    True

			    (and (not cancelled) (@ deviceSelected 'oldSlots))
				    (and (scrGetItem gScreen) 
					    (not (find (@ deviceSelected 'oldSlots) (itmGetInstallPos (scrGetItem gScreen))))
					    )
							
			    (@ deviceSelected 'slotPosIndex)
				    (eq (@ deviceSelected 'slotPosIndex) (if (not (scrGetItem gScreen)) (@ (scrGetListEntry gScreen) 'slotPosIndex)))
						
			    (@ deviceSelected 'installPos)
				    (eq (@ deviceSelected 'installPos) (if (scrGetItem gScreen) (itmGetInstallPos (scrGetItem gScreen))))
						
			    (@ deviceSelected 'installCategory)
				    (eq (@ deviceSelected 'installCategory) (if (scrGetItem gScreen) (itmGetProperty (scrGetItem gScreen) 'category) (@ (scrGetListEntry gScreen) 'category)))
						
			    True
			    )
		    )            
      	        ))
From what little I can understand it would seem that (@ deviceSelected 'installPos) is needed when we return to the Weapons screen to set the cursor back on the weapon.

<OnPaneInit> in the Weapons screen uses this code

Code: Select all

	;Remember selection.
(scrSetData gScreen 'deviceSelected { installPos:(itmGetInstallPos theItem) })
if the cursor is on a device. This would seem to be what is needed in rpgSelectorInitialItem.

And here's the "Get Ammo" action code.

Code: Select all

<Action id="actionGetAmmo">
	(block Nil
		(setq itemStation (sysCreateStation &vtD789GodItemsVirtualStation; Nil))
		(setq itemList (itmGetTypes (cat "m +launchedBy:" (itmGetType (scrGetItem gScreen)) ";")))
		(enum itemList theItem (objAddItem itemStation theItem 1))

		(scrShowScreen gScreen &dsD789GodGetItemsDockscreen; {
			shipObj: shipObj
			station: itemStation
			scrTitle: (cat "Ammunition for " (itmGetName (scrGetItem gScreen) 'short))
			})
	)
</Action>
I've tried a number of variations including adding scrSetData gScreen 'deviceSelected info in the "Get Ammo" action code as is done in the "Install" action (which does preserve the cursor placement) but cannot get any result but the cursor appearing in the default slot.

Can anyone see what is needed to get the cursor to return to the selected device? The code in rpgSelectorInitialItem is way over my head.

Also attached is a development version of the Taipan.
To see the problem select
Ship's Interior
Ship Dock Services
Weapons
Place the cursor on the Akan 600
Select the "Get Ammo" action.
Select "Back" from the ammo screen.
The cursor will be on the archcannon, not the Akan as is desired.

TIA.
Attachments
buggy Taipan for testing.zip
(994.03 KiB) Downloaded 12 times
DockscreenCode NOT A MOD.xml
(21.08 KiB) Downloaded 13 times

giantcabbage
Commonwealth Pilot
Commonwealth Pilot
Posts: 96
Joined: Thu Apr 07, 2011 9:05 pm

Wed May 30, 2018 5:23 pm

It looks like you are using rpgSelectorInitialItem correctly and there is nothing wrong in dsD789GodWeaponsDockscreen..

I think the problem is actionBack in dsD789GodGetItemsDockscreen - you are returning to the first screen with another scrShowScreen command. This means you are not returning to the first screen, but instead you are opening a new version of the first screen.

Instead you should make dsD789GodGetItemsDockscreen a nestedScreen. i.e.

Code: Select all

<Dockscreen UNID= "&dsD789GodGetItemsDockscreen;"
	name=			"=(if (@ gData 'scrTitle) (@ gData 'scrTitle))"
	type=			"itemPicker"
	nestedScreen=	"true"
	>
and change the Back actions to:

Code: Select all

<Action id="actionBack" cancel="1">
	(scrExitScreen gScreen)
</Action>

relanat
Militia Captain
Militia Captain
Posts: 600
Joined: Tue Nov 05, 2013 9:56 am

Mon Jun 04, 2018 2:26 am

Thank you. That fixed it. And actionGetMissiles returns the cursor to the installed launcher now as well.
I have been moving away from nestedScreens when several other screens can navigate into one because it can lead to looping dockscreens. But knowing this
This means you are not returning to the first screen, but instead you are opening a new version of the first screen.
means I can consider them a bit more now. Vital info. Thanks again.

Post Reply