-
Notifications
You must be signed in to change notification settings - Fork 8
Common Tasks
For the most part, you can just use the Actor
event OnPlayerLoadGame
. However, this won't work the first time your script is loaded on a save load. See OnPlayerLoadGame
for details on running code on the first load of your mod as well.
In Papyrus, strings are used for many things, such as naming objects with SetDisplayName("myName")
or identifying keywords with Game.GetKeyword("myKeyword")
. However, there are some peculiarities that you need to understand if you want to use strings properly. Papyrus strings are stored in a case-insensitive cache. So, if I create a string in Papyrus like this:
ObjectReference myMudcrab ; Set somewhere earlier in the script
String myMudcrabName = "Mudcrab"
myMudcrab.SetDisplayName(myMudcrabName + " Soul")
This will actually not work as expected. Rather than ending up with a Mudcrab named "Mudcrab Soul", you'll end up with "mudcrab Soul". This is because the string "mudcrab" is already in the Papyrus case insensitive cache from the vanilla game's data. When you define a string with the same characters as a string already in the cache, your string just points to the existing string in the cache.
To solve this, you'll need to avoid directly defining a string that already exists in the cache. If you're doing something very small scale, you could do this all in Papyrus. As an example, if I just want to solve the above situation, I could:
myMudcrab.SetDisplayName("Mudcrab Soul")
"Mudcrab Soul" is not a string that is already defined in the cache, so it will use the capitalization defined in my string when it is added to the cache as a new string.
However, the above solution has the obvious drawback that it assumes you can hard-code your strings fully written. However, it's more likely in a scripting information that you'll need to get components of your string from other locations. For example, you might need to GetDisplayName
on an ObjectReference
and then concatenate that string with proper capitalization into a string of your own making. For this you could write an SKSE plugin that does all of this in C++ where you can control the capitalization of strings and return a fully formed String to Papyrus that doesn't have to worry about clashing with an existing string on the cache (As long as the string you create in your SKSE plugin isn't already in the cache).