Editing Arcane University:Scripting Best Practices

Jump to: navigation, search

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.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 17: Line 17:
 
#Before making a new script, see if there's an existing default script you can use, e.g. <code>defaultSetStageOnDeath</code> or <code>defaultPlayerEnableDisableLinkedRef</code>.
 
#Before making a new script, see if there's an existing default script you can use, e.g. <code>defaultSetStageOnDeath</code> or <code>defaultPlayerEnableDisableLinkedRef</code>.
 
#Don’t start properties, variables, functions, or any type of Papyrus identifier with a number --- the compiler will fail (i.e. <code>123function()</code> fails).
 
#Don’t start properties, variables, functions, or any type of Papyrus identifier with a number --- the compiler will fail (i.e. <code>123function()</code> fails).
#Avoid constant polling with short intervals whenever possible. There are almost always more efficient ways of doing something, such as events that detect what you are trying to poll. If you use a while loop or <code>OnUpdate</code>, make sure there is some failsafe to exit the loop/stop the updates.
+
#Avoid constant polling with short intervals whenever possible (see previous lesson). There are almost always more efficient ways of doing something, such as events that detect what you are trying to poll. If you use a while loop or <code>OnUpdate</code>, make sure there is some failsafe to exit the loop/stop the updates.
 
#Avoid long <code>Wait()</code> functions (this can cause issues with stack dumping: https://www.creationkit.com/index.php?title=User:DavidJCobb/Stack_dumping). Instead, use <code>RegisterForSingleUpdate</code>/<code>OnUpdate</code> or <code>RegisterForSingleUpdateGameTime</code>/<code>OnUpdateGameTime</code>.
 
#Avoid long <code>Wait()</code> functions (this can cause issues with stack dumping: https://www.creationkit.com/index.php?title=User:DavidJCobb/Stack_dumping). Instead, use <code>RegisterForSingleUpdate</code>/<code>OnUpdate</code> or <code>RegisterForSingleUpdateGameTime</code>/<code>OnUpdateGameTime</code>.
 
#If you make an ObjectReference or an Actor a property, that ref will become persistent (always loaded). Avoid this when possible and use linkedrefs or referencealiases.
 
#If you make an ObjectReference or an Actor a property, that ref will become persistent (always loaded). Avoid this when possible and use linkedrefs or referencealiases.
Line 26: Line 26:
 
#If you’ve got an empty state, make sure it remains empty; otherwise the event in it will still be processed, which takes away a big benefit to empty states (not having events even be processed).
 
#If you’ve got an empty state, make sure it remains empty; otherwise the event in it will still be processed, which takes away a big benefit to empty states (not having events even be processed).
 
#Avoid piling too much onto your script at once, especially if it has to be run often – too much activity can be hard on Papyrus. States can be useful for limiting what is running at a given point in time.
 
#Avoid piling too much onto your script at once, especially if it has to be run often – too much activity can be hard on Papyrus. States can be useful for limiting what is running at a given point in time.
#Avoid convenience functions – use <code>GetReference() as Actor</code> instead of <code>GetActorRef()</code>, <code>GetActorValue()</code> instead of <code>GetAV()</code>, etc...
+
#Avoid convenience functions – use <code>GetReference()</code> as Actor instead of <code>GetActorRef()</code>, <code>GetActorValue()</code> instead of <code>GetAV()</code>, etc...
 
#Sometimes there are Condition Functions that do not have Papyrus equivalents (e.g. <code>IsPlayerInRegion</code>). If you need to access these conditions in a script, two possibilities are:
 
#Sometimes there are Condition Functions that do not have Papyrus equivalents (e.g. <code>IsPlayerInRegion</code>). If you need to access these conditions in a script, two possibilities are:
 
##'''Use a spell:''' Make a constant effect magic effect that sets a global to 1 on effect start and 0 on effect end. Then, make an ability that has this effect, and condition the effect using the condition function you want to use in your Papyrus script. Add the ability to the player (or to a player quest alias). Then, add this global variable as a script property. You can check if it is equal to 1 or 0 to see if your condition is met.
 
##'''Use a spell:''' Make a constant effect magic effect that sets a global to 1 on effect start and 0 on effect end. Then, make an ability that has this effect, and condition the effect using the condition function you want to use in your Papyrus script. Add the ability to the player (or to a player quest alias). Then, add this global variable as a script property. You can check if it is equal to 1 or 0 to see if your condition is met.

Please note that all contributions to Beyond Skyrim are considered to be released under the Creative Commons Attribution-ShareAlike (see Beyond Skyrim Wiki: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!

To edit this page, please answer the question that appears below (more info):

Cancel | Editing help (opens in new window)

Template used on this page: