Open main menu
Home
Random
Log in
Settings
About the CreationKit Wiki
Disclaimers
the CreationKit Wiki
Search
Editing
Complete Example Scripts
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=Cycle Through a List of Objects and Perform an Action on Each Object(FormLists)= This example script cycles through a List of objects, known as a [[Formlist]], and enables them all if they are disabled, and disables them if they are enabled, each time the player character walks through a chosen trigger volume. If you use a [[Formlist]] of special effects, this would cause all the many special effects you have in the formlist to disappear or reappear each time you walk through the trigger volume. <syntaxhighlight lang="papyrus">ScriptName RamaFormListExampleScript extends ObjectReference Actor Property PlayerREF Auto ; Least 'expensive' way to refer to the player FormList Property ListOfObjectsFLST Auto ; see notes after script for more info on this property Event OnTriggerEnter(ObjectReference akActionRef) If akActionRef == PlayerREF Int iIndex = ListOfObjectsFLST.GetSize() ; Indices are offset by 1 relative to size While iIndex iIndex -= 1 ObjectReference kReference = ListOfObjectsFLST.GetAt(iIndex) As ObjectReference ; Note that you must typecast the entry from the formlist using 'As'. If kReference.IsEnabled() kReference.Disable() Else ; If kReference.IsDisabled() kReference.Enable() EndIf EndWhile EndIf EndEvent</syntaxhighlight> '''To Make This Script Work''' * This script runs on a OnTriggerEnter event, so you must create a trigger volume. See the [[Complete_Example_Scripts#A_Trigger_That_Detects_When_The_Player_Enters|script example above]] for details on this. * Remember to add this example script to the trigger volume object that you create, so you have an actual instance of this script in your level. * You must create a formlist of the objects you want to cycle through in this script example. [[Image:Formlist_populating.png]] 1. Go to the miscellaneous section of the Object Window and click on FormLists, 2. then right click to make a new FormList 3. In your cell view, hold shift and select all of the forms you want to add to the formlist, these could be actors or special effects, activators, or any other kind of form. Name all the forms you want to include from your cell in a similar way so they can be easily selected as a group using shift. 4. Drag the selected forms into the window containing your new formlist information. 5. Make sure to only add forms to your formlist that are all of the same type. Do not mix actors and activators for example. * Now you must modify the property of this script example instance, which is present on your trigger volume. Edit the property so that it points to EditorID of your formlist that you just created. * For this script example, I was simply enabling or disabling the objects in the list, so make sure that your formlist contains forms that will react when you enable/disable them. Actors or special effects (look up FX in the *All section of the Object Window) are good forms to start with. '''Uses:''' * Any time you have a long list of script properties you want to perform an action on, you can make a formlist instead, and use the while loop to make your coding life Heavenly. * Systematically add a certain amount of health or other characteristic to 10 or 2000 actors / creatures to make then stronger or weaker or give them a certain skill (use setAV actor function) * Use enable/disable to make a whole bunch of special effect objects (they start with FX in editor) appear or disappear Enjoy!
Summary:
Please note that all contributions to the CreationKit Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see
CreationKit:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)