Difference between revisions of "Utility Script"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>Behippo
(→‎SKSE Global Functions: - Added SKSE Global Functions list.)
 
(8 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[[Category:Scripting]]
[[Category:Papyrus]]
[[Category:Script Objects]]
Collection of generic utility global functions
Collection of generic utility global functions


Line 11: Line 7:


== Properties ==
== Properties ==
None
== Member Functions ==
None
None


== Global Functions ==
== Global Functions ==
'''string Function [[GameTimeToString - Utility|GameTimeToString]]()'''
*Converts a float game time (in terms of game days passed) to a string detailing the date and time it represents.


'''float Function [[GetCurrentGameTime - Utility|GetCurrentGameTime]]()'''
:'''String [[GameTimeToString - Utility|GameTimeToString]]()'''
*Obtains the current game time in terms of game days passed (the same as the global variable of a similar name)
:*Converts a float game time (in terms of game days passed) to a string detailing the date and time it represents.
 
:'''Float [[GetCurrentGameTime - Utility|GetCurrentGameTime]]()'''
:*Obtains the current game time in terms of game days passed (the same as the global variable of a similar name)
 
:'''Float [[GetCurrentRealTime - Utility|GetCurrentRealTime]]()'''
:*Obtains the number of real-world seconds that have passed since the game has launched (ignoring time alt-tabbed away, or other cases where the game might be frozen)


'''float Function [[GetCurrentRealTime - Utility|GetCurrentRealTime]]()'''
:'''Bool [[IsInMenuMode - Utility|IsInMenuMode]]()'''
*Obtains the number of real-world seconds that have passed since the game has launched (ignoring time alt-tabbed away, or other cases where the game might be frozen)
:*Returns whether the game is currently in "menu mode" or not.


'''bool Function [[IsInMenuMode - Utility|IsInMenuMode]]()'''
:'''Float [[RandomFloat - Utility|RandomFloat]](Float ''afMin'', Float ''afMax'')'''
*Returns whether the game is currently in "menu mode" or not.
:*Generates a random float between the minimum and maximum (inclusive)


'''float Function [[RandomFloat - Utility|RandomFloat]](float afMin, float afMax)'''
:'''Int [[RandomInt - Utility|RandomInt]](Int ''aiMin'', Int ''aiMax'')'''
*Generates a random float between the minimum and maximum (inclusive)
:*Generates a random integer between the minimum and maximum (inclusive)


'''int Function [[RandomInt - Utility|RandomInt]](int aiMin, int aiMax)'''
:'''[[SetINIFloat - Utility|SetINIFloat]](String ''ini'', Float ''value'')'''
*Generates a random integer between the minimum and maximum (inclusive)
:*Sets the float value of the associated INI entry.


'''Function [[Wait - Utility|Wait]](float afSeconds)'''
:'''[[SetINIInt - Utility|SetINIInt]](String ''ini'', Int ''value'')'''
*Pauses the script for at least the specified time (latent). Does not count time spent in a menu.
:*Sets the integer value of the associated INI entry.


'''Function [[WaitGameTime - Utility|WaitGameTime]](float afHours)'''
:'''[[SetINIBool - Utility|SetINIBool]](String ''ini'', Bool ''value'')'''
*Pauses the script for at least the specified amount of game time (latent).
:*Sets the boolean value of the associated INI entry.


'''Function [[WaitMenuMode - Utility|WaitMenuMode]](float afSeconds)'''
:'''[[SetINIString - Utility|SetINIString]](String ''ini'', String ''value'')'''
*Pauses the script for at least the specified time (latent). ''Does'' count time spent in a menu.
:*Sets the string value of the associated INI entry.
 
:'''[[Wait - Utility|Wait]](Float ''afSeconds'')'''
:*Pauses the script for at least the specified time (latent). Does not count time spent in a menu.
 
:'''[[WaitGameTime - Utility|WaitGameTime]](Float ''afHours'')'''
:*Pauses the script for at least the specified amount of game time (latent).
 
:'''[[WaitMenuMode - Utility|WaitMenuMode]](Float ''afSeconds'')'''
:*Pauses the script for at least the specified time (latent). ''Does'' count time spent in a menu.
 
:'''Int [[GetCurrentMemory - Utility|GetCurrentMemory]]()'''
:*Returns the currently used memory amount. To use any other memory functions this must be called first as it sets up the memory stats used by the other functions.
 
:'''Int [[GetBudgetCount - Utility|GetBudgetCount]]()'''
:*
 
:'''Int [[GetCurrentBudget - Utility|GetCurrentBudget]](Int ''aiBudgetNumber'')'''
:*
 
:'''Bool [[OverBudget - Utility|OverBudget]](Int ''aiBudgetNumber'')'''
:*
 
:'''String [[GetBudgetName- Utility|GetBudgetName]](Int ''aiBudgetNumber'')'''
:*
 
=== Global Functions Only Available in Beta ===
Frame Rate Capture functions were only available during beta versions, and are added here for completeness.
:'''String [[CaptureFrameRate - Utility|CaptureFrameRate]](Int ''numFrames'')'''
:*Gets a string describing the frame rate for a certain number of frames, the string returned will never be longer then 1,000 characters and is separated by commas.
 
:'''[[StartFrameRateCapture - Utility|StartFrameRateCapture]]()'''
:*Starts a frame rate capture.
 
:'''[[EndFrameRateCapture - Utility|EndFrameRateCapture]]()'''
:*Ends a frame rate capture.
 
:'''[[GetAverageFrameRate - Utility|GetAverageFrameRate]]()'''
:*Returns the average frame rate during the capture.
 
:'''[[GetMinFrameRate - Utility|GetMinFrameRate]]()'''
:*Returns the minimum frame rate during the capture.
 
:'''[[GetMaxFrameRate - Utility|GetMaxFrameRate]]()'''
:*Returns the maximum frame rate during the capture.


== SKSE Global Functions ==
== SKSE Global Functions ==
'''float Function [[GetINIFloat - Utility|GetINIFloat]](string ini)'''
*Returns the float value of the associated INI entry.


'''int Function [[GetINIInt - Utility|GetINIInt]](string ini)'''
:'''Float [[GetINIFloat - Utility|GetINIFloat]](String ''ini'')'''
*Returns the integer value of the associated INI entry.
:*Returns the float value of the associated INI entry.
 
:'''Int [[GetINIInt - Utility|GetINIInt]](String ''ini'')'''
:*Returns the integer value of the associated INI entry.
 
:'''Bool [[GetINIBool - Utility|GetINIBool]](String ''ini'')'''
:*Returns the boolean value of the associated INI entry.
 
:'''String [[GetINIString - Utility|GetINIString]](String ''ini'')'''
:*Returns the string value of the associated INI entry.
 
 
'''Be careful when using the functions below.''' It is possible to create arrays longer than 128 elements, and ''size'' is treated as an unsigned integer. Negative numbers will produce extremely large values, which can cause major issues.
 
:'''Float[] [[CreateFloatArray - Utility|CreateFloatArray]](Int ''size'', Float ''fill'' = 0.0)'''
:*Creates and returns a Float array with length ''size'', with each element initialized to ''fill''.
 
:'''Int[] [[CreateIntArray - Utility|CreateIntArray]](Int ''size'', Int ''fill'' = 0)'''
:*Creates and returns an Int array with length ''size'', with each element initialized to ''fill''.
 
:'''Bool[] [[CreateBoolArray - Utility|CreateBoolArray]](Int ''size'', Bool ''fill'' = False)'''
:*Creates and returns a Bool array with length ''size'', with each element initialized to ''fill''.
 
:'''String[] [[CreateStringArray - Utility|CreateStringArray]](Int ''size'', String ''fill'' = "")'''
:*Creates and returns a String array with length ''size'', with each element initialized to ''fill''.
 
:'''Form[] [[CreateFormArray - Utility|CreateFormArray]](Int ''size'', Form ''fill'' = None)'''
:*Creates and returns a String array with length ''size'', with each element initialized to ''fill''.
 
:'''Alias[] [[CreateAliasArray - Utility|CreateAliasArray]](Int ''size'', Alias ''fill'' = None)'''
:*Creates and returns an Alias array with length ''size'', with each element initialized to ''fill''.
 
:'''float[] [[ResizeFloatArray - Utility|ResizeFloatArray]](float[] ''source'', int ''size'', float ''fill'' = 0.0)'''
:*Resizes the ''source'' Float Array to be of length ''size'', in case it is grown, initializes uninitialized elements to ''fill''.
 
:'''int[] [[ResizeIntArray - Utility|ResizeIntArray]](int[] ''source'', int ''size'', int ''fill'' = 0)'''
:*Resizes the ''source'' Int Array to be of length ''size'', in case it is grown, initializes uninitialized elements to ''fill''.
 
:'''bool[] [[ResizeBoolArray - Utility|ResizeBoolArray]](bool[] ''source'', int ''size'', bool ''fill'' = false)'''
:*Resizes the ''source'' Bool Array to be of length ''size'', in case it is grown, initializes uninitialized elements to ''fill''.


'''bool Function [[GetINIBool - Utility|GetINIBool]](string ini)'''
:'''string[] [[ResizeStringArray - Utility|ResizeStringArray]](string[] ''source'', int ''size'', string ''fill'' = "")'''
*Returns the boolean value of the associated INI entry.
:*Resizes the ''source'' String Array to be of length ''size'', in case it is grown, initializes uninitialized elements to ''fill''.


'''string Function [[GetINIString - Utility|GetINIString]](string ini)'''
:'''Form[] [[ResizeFormArray - Utility|ResizeFormArray]](Form[] ''source'', int ''size'', Form ''fill'' = None)'''
*Returns the string value of the associated INI entry.
:*Resizes the ''source'' Form Array to be of length ''size'', in case it is grown, initializes uninitialized elements to ''fill''.


== Member Functions ==
:'''Alias[] [[ResizeFormArray - Utility|ResizeAliasArray]](Alias[] ''source'', int ''size'', Alias ''fill'' = None)'''
:*Resizes the ''source'' Alias Array to be of length ''size'', in case it is grown, initializes uninitialized elements to ''fill''.
 
 
==Events==
None
None


== Events ==
[[Category:Scripting]]
None
[[Category:Papyrus]]
[[Category:Script Objects]]
[[Category:SKSE]]
[[Category:SKSE Script Objects]]

Latest revision as of 07:26, 23 June 2023

Collection of generic utility global functions

Definition[edit | edit source]

ScriptName Utility

Properties[edit | edit source]

None


Member Functions[edit | edit source]

None

Global Functions[edit | edit source]

String GameTimeToString()
  • Converts a float game time (in terms of game days passed) to a string detailing the date and time it represents.
Float GetCurrentGameTime()
  • Obtains the current game time in terms of game days passed (the same as the global variable of a similar name)
Float GetCurrentRealTime()
  • Obtains the number of real-world seconds that have passed since the game has launched (ignoring time alt-tabbed away, or other cases where the game might be frozen)
Bool IsInMenuMode()
  • Returns whether the game is currently in "menu mode" or not.
Float RandomFloat(Float afMin, Float afMax)
  • Generates a random float between the minimum and maximum (inclusive)
Int RandomInt(Int aiMin, Int aiMax)
  • Generates a random integer between the minimum and maximum (inclusive)
SetINIFloat(String ini, Float value)
  • Sets the float value of the associated INI entry.
SetINIInt(String ini, Int value)
  • Sets the integer value of the associated INI entry.
SetINIBool(String ini, Bool value)
  • Sets the boolean value of the associated INI entry.
SetINIString(String ini, String value)
  • Sets the string value of the associated INI entry.
Wait(Float afSeconds)
  • Pauses the script for at least the specified time (latent). Does not count time spent in a menu.
WaitGameTime(Float afHours)
  • Pauses the script for at least the specified amount of game time (latent).
WaitMenuMode(Float afSeconds)
  • Pauses the script for at least the specified time (latent). Does count time spent in a menu.
Int GetCurrentMemory()
  • Returns the currently used memory amount. To use any other memory functions this must be called first as it sets up the memory stats used by the other functions.
Int GetBudgetCount()
Int GetCurrentBudget(Int aiBudgetNumber)
Bool OverBudget(Int aiBudgetNumber)
String GetBudgetName(Int aiBudgetNumber)

Global Functions Only Available in Beta[edit | edit source]

Frame Rate Capture functions were only available during beta versions, and are added here for completeness.

String CaptureFrameRate(Int numFrames)
  • Gets a string describing the frame rate for a certain number of frames, the string returned will never be longer then 1,000 characters and is separated by commas.
StartFrameRateCapture()
  • Starts a frame rate capture.
EndFrameRateCapture()
  • Ends a frame rate capture.
GetAverageFrameRate()
  • Returns the average frame rate during the capture.
GetMinFrameRate()
  • Returns the minimum frame rate during the capture.
GetMaxFrameRate()
  • Returns the maximum frame rate during the capture.

SKSE Global Functions[edit | edit source]

Float GetINIFloat(String ini)
  • Returns the float value of the associated INI entry.
Int GetINIInt(String ini)
  • Returns the integer value of the associated INI entry.
Bool GetINIBool(String ini)
  • Returns the boolean value of the associated INI entry.
String GetINIString(String ini)
  • Returns the string value of the associated INI entry.


Be careful when using the functions below. It is possible to create arrays longer than 128 elements, and size is treated as an unsigned integer. Negative numbers will produce extremely large values, which can cause major issues.

Float[] CreateFloatArray(Int size, Float fill = 0.0)
  • Creates and returns a Float array with length size, with each element initialized to fill.
Int[] CreateIntArray(Int size, Int fill = 0)
  • Creates and returns an Int array with length size, with each element initialized to fill.
Bool[] CreateBoolArray(Int size, Bool fill = False)
  • Creates and returns a Bool array with length size, with each element initialized to fill.
String[] CreateStringArray(Int size, String fill = "")
  • Creates and returns a String array with length size, with each element initialized to fill.
Form[] CreateFormArray(Int size, Form fill = None)
  • Creates and returns a String array with length size, with each element initialized to fill.
Alias[] CreateAliasArray(Int size, Alias fill = None)
  • Creates and returns an Alias array with length size, with each element initialized to fill.
float[] ResizeFloatArray(float[] source, int size, float fill = 0.0)
  • Resizes the source Float Array to be of length size, in case it is grown, initializes uninitialized elements to fill.
int[] ResizeIntArray(int[] source, int size, int fill = 0)
  • Resizes the source Int Array to be of length size, in case it is grown, initializes uninitialized elements to fill.
bool[] ResizeBoolArray(bool[] source, int size, bool fill = false)
  • Resizes the source Bool Array to be of length size, in case it is grown, initializes uninitialized elements to fill.
string[] ResizeStringArray(string[] source, int size, string fill = "")
  • Resizes the source String Array to be of length size, in case it is grown, initializes uninitialized elements to fill.
Form[] ResizeFormArray(Form[] source, int size, Form fill = None)
  • Resizes the source Form Array to be of length size, in case it is grown, initializes uninitialized elements to fill.
Alias[] ResizeAliasArray(Alias[] source, int size, Alias fill = None)
  • Resizes the source Alias Array to be of length size, in case it is grown, initializes uninitialized elements to fill.


Events[edit | edit source]

None