Scripting Best Practices: Formlists vs Form Checks?

Post » Tue Feb 24, 2015 1:04 am

Recently returned to modding and currently scripting some auto-sorting chests for a player home.
One thing I'm a little rusty on are best practices. Whilst trying to exhaustively test the feature for any minor flaws I've noticed that some items/use-cases can take a while to "process". I'd like these scripts to execute as fast as possible, so what is more efficient to use? A Formlist, or to check a bunch of Base-Item Forms?

Here is my code so far:

Spoiler
scriptname _sgaAutosortContainer extends objectreference{Original script by SjoggaThis script should be attached to containers.}import gameimport utilityformlist property ListCookedFood auto hiddenformlist property ListOre auto hiddenformlist property ListItemsSmithing auto hiddenformlist property MDHMaskList Auto hiddenformlist property MDHFormList01 Auto hiddenformlist property MDHFormList02 Auto hiddenbool Property bypassGlobalCheck = false auto{Default: FalseSet True if you want this container to ignore the GlobalAutoSort-variable and sort items anyway}ObjectReference property master auto{The ObjectReference attached with the _sgaAutosortMaster-script}bool property bypassPlayerCheck = false auto{Default: False. Set True if you want items added by containers other than the players to be sorted as well.}event OnInit()	ListCookedFood = (master as _sgaAutosortMaster).ListCookedFood	ListOre = (master as _sgaAutosortMaster).ListOre	ListItemsSmithing = (master as _sgaAutosortMaster).ListItemsSmithing	MDHMaskList = (master as _sgaAutoSortMaster).MDHMaskList	MDHFormList01 = (master as _sgaAutoSortMaster).MDHFormList01	MDHFormList02 = (master as _sgaAutoSortMaster).MDHFormList02endEventevent OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)	; ===============================================================================================================================	;You can identify items in three ways	;	- the Form of the object, such as Weapon and Armor. Very reliable, but not very specific.	;	  To preform a form-check, preform a type cast on akBaseItem: 			if(akBaseItem as SoulGem) ; true if akBaseItem is a Soul Gem		;	- Keywords, more specific than a form-check, but less reliable.	;	  To preform a keyword-check, use the hasKeyWord-function: 			if(akBaseItem.hasKeyWord(KeywordLeather)) ; true if akBaseItem has KeywordLeather		;	- Compare if the item matches the exact form ID of a property. 	;	  To preform an id-match, simply compare the item added with a property:	if(akBaseItem == ItemGold) ; true if akBaseItem is a gold coin	;	  This is usally done on items sent in by a form list.	;	;	Note that this script uses the variables of the _sgaAutosortMaster-script, which is attached to the master-objectreference	;	This saves you a lot of work, since you only have to set the vaiables once in the Creation Kit.			; ================================================================================================================================		if(akSourceContainer != getPlayer() && !bypassPlayerCheck)		return	endif	int globalValue = http://forums.bethsoft.com/topic/1514449-scripting-best-practices-formlists-vs-form-checks/(master as _sgaAutosortMaster).GlobalAutoSort.getValueInt()	if(globalValue!=1 && !bypassGlobalCheck) 		return	endif		int j = 0;=================== Empty Formlists;=================== If I define some empty formlists and"sort" them into dummy containers I can later "fill" those formlists and rename those containers at leisure. This should be extremely helpful if I  later want mod-added content to be sortableif MDHFormList01.HasForm(akBaseItem)		int i = 0	while i

You should be able to see where I use a formlist for the Dragon Priest Masks, and where I simply check the forms for the Dragon Claws.

User avatar
Nienna garcia
 
Posts: 3407
Joined: Wed Apr 25, 2007 3:23 am

Return to V - Skyrim