finding lists in lists code help please

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

The inventory mod I'm working on has a "Find" feature as seen in the Captain's Log mod. Items are listed on the screen in the system where they are so players can find them again if they aren't in that system.
It use screen input text to search for matches in the item name.

But the code is a little too much for me.
The data is stored in list form.
objID, name, nodeID, 'visited status' and a list of uninstalled items in the station.

Code: Select all

matchingStations
((18565 "Pergium Fuel & Supplies" SE Visited ((16444 -16777078) (16458 -16777215) (16788 -16777185) (16422 -16777194))) (18609 "Sisters of Domina" SE Visited ((16523 -16777213) (16572 -16777215) (16560 -16777215) (16447 -16777213) (16431 -16777210))))
The items to be searched for are also a list, in this case items containing "h" in their name.

Code: Select all

sortedMatchingItemList
((16431 -16777210) (16444 -16777078) (16788 -16777185))
I can sort of get it working.

Code: Select all

(enum sortedMatchingItemList theItem
	(enum matchingStations theStationEntry
		(block Nil
			(if (find (@ theStationEntry 4) theItem)
				(lnkAppend entryToAdd
					(cat
						(itmGetName theItem) " "
						(itmGetCount theItem) " - "
						(@ theStationEntry 1)
					)
				)
			)
		)
	)
)
produces the right format but way too many times.

Code: Select all

entryToAdd
("roll of hyperfiber 6 - Sisters of Domina" "helium³ fuel rod 138 - Pergium Fuel & Supplies" "tank of hydrogen gas 31 - Pergium Fuel & Supplies" "roll of hyperfiber 6 - Sisters of Domina" "helium³ fuel rod 138 - Pergium Fuel & Supplies" "tank of hydrogen gas 31 - Pergium Fuel & Supplies" "roll of hyperfiber 6 - Sisters of Domina" "helium³ fuel rod 138 - Pergium Fuel & Supplies" "tank of hydrogen gas 31 - Pergium Fuel & Supplies" "roll of hyperfiber 6 - Sisters of Domina" "helium³ fuel rod 138 - Pergium Fuel & Supplies" "tank of hydrogen gas 31 - Pergium Fuel & Supplies" "roll of hyperfiber 6 - Sisters of Domina" "helium³ fuel rod 138 - Pergium Fuel & Supplies" "tank of hydrogen gas 31 - Pergium Fuel & Supplies" "roll of hyperfiber 6 - Sisters of Domina" "helium³ fuel rod 138 - Pergium Fuel & Supplies" "tank of hydrogen gas 31 - Pergium Fuel & Supplies" "roll of hyperfiber 6 - Sisters of Domina" "helium³ fuel rod 138 - Pergium Fuel & Supplies" "tank of hydrogen gas 31 - Pergium Fuel & Supplies")
Any tips on generating just the one lot of entries?
I guess it may need 'for' or 'loop' instead of one of the 'enum's but I don't want to waste even more time on it.
Stupid code. Do what I want, not what I typed in!
NMS
Militia Captain
Militia Captain
Posts: 569
Joined: Tue Mar 05, 2013 8:26 am

Is entryToAdd a global variable that you aren't clearing each time, by any chance? That would cause the new results to be appended to the previous results each time you run it. If that's not the case, then I'd guess there are repeated entries in sortedMatchingItemList.

However, there's probably a better approach. For one thing, if multiple stations had identical items (including quantity), I would guess each one would get added to sortedMatchingItemList, then each station would get an entry in the result for each item in the list. For another, I suspect you're duplicating a lot of work by searching stations for items, adding the items to a list, processing them, then searching the stations again to see which ones have which items. It seems better to create a list of item types you're looking for, then search the stations using objHasItem or item lists using itmMatches or itmGetType, and add the result to the output when you find a match.

If that doesn't clear things up, I might need to see the whole mod.
relanat
Militia Captain
Militia Captain
Posts: 941
Joined: Tue Nov 05, 2013 9:56 am

Is entryToAdd a global variable that you aren't clearing each time, by any chance?
Aah, yes. That's it. Using 'enum' twice with three items is giving 6 results added to each other. Usually I have something like (setq entryToAdd Nil) just above 'lnkAppend' code but I can't see that working here.

Also the duplication is unfortunately necessary so station items can be searched when the player is in other systems.

I've shelved this for now and used a simpler single item search in the mod. Eventually a multiple search displayed using scrSetDisplayText will replace it but I need to work out a final format for it. Thanks.
Stupid code. Do what I want, not what I typed in!
Post Reply