Complete Example Scripts: Difference between revisions
Jump to navigation
Jump to search
m
→Cycle Through a List of Objects and Perform an Action on Each Object(FormLists): Condensed to prevent carpel tunnel/standardized capitalization for legibility
imported>JustinOther |
imported>JustinOther m (→Cycle Through a List of Objects and Perform an Action on Each Object(FormLists): Condensed to prevent carpel tunnel/standardized capitalization for legibility) |
||
| Line 124: | Line 124: | ||
===Cycle Through a List of Objects and Perform an Action on Each Object(FormLists)=== | ===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. | 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. | 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. | ||
<source lang="papyrus">ScriptName RamaFormListExampleScript extends ObjectReference | |||
Int iCurIndex | |||
Int iTotal | |||
FormList Property ListOfObjectsFLST Auto ; see notes after script for more info on this property | |||
ObjectReference akReference | |||
; | |||
Event onTriggerEnter(ObjectReference akActionRef) | |||
If akActionRef == Game.GetPlayer()) | |||
akReference = ListOfObjectsFLST.GetAt(0) as ObjectReference ; I use ObjectReference so that IsEnabled() becomes accessible. Use Actor if you want to perform actor functions and the formlist contains actors. | |||
iTotal = ListOfObjectsFLST.GetSize() ; Initialize | |||
iCurIndex = 0 ; test index 0 entry to see if all are enabled or disabled | |||
If akReference.IsEnabled() | |||
While(iCurIndex < iTotal) | |||
akReference = ListOfObjectsFLST.GetAt(curIndex) as ObjectReference ; Note that you must typecast the entry from the formlist using "as." | |||
akReference.Disable() | |||
iCurIndex += 1 | |||
; | EndWhile | ||
Else | |||
While(curIndex < iTotal) | |||
akReference = ListOfObjectsFLST.GetAt(curIndex) as ObjectReference | |||
akReference.Enable() | |||
curIndex += 1 | curIndex += 1 | ||
EndWhile | |||
EndIf | |||
EndIf | |||
EndEvent</source> | |||
</source> | |||
'''To Make This Script Work''' | '''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. | |||
* This script runs on a | |||
* 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. | * 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. | * You must create a formlist of the objects you want to cycle through in this script example. | ||
[[Image:Formlist_making_a_formlist_and_populating_it.jpg]] | [[Image:Formlist_making_a_formlist_and_populating_it.jpg]] | ||
1. Go to the miscellaneous section of the Object Window and click on | 1. Go to the miscellaneous section of the Object Window and click on FormLists, | ||
2. then right click to make a new FormList | |||
2. then right click to make a new | |||
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. | 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. | 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. | 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. | * 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. | 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. | * 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:''' | '''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. | * 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) | * 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 | * Use enable/disable to make a whole bunch of special effect objects (they start with FX in editor) appear or disappear | ||
Enjoy! | Enjoy! | ||