Difference between revisions of "String Formatting"

538 bytes added ,  13:31, 7 May 2017
no edit summary
imported>Odessa
(Created, consolidated info from existing articles and OBSE docs)
 
imported>Pintocat
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{Template:Community_Wiki}}
Some commands take a format string as a parameter. Format strings are actually a collection of arguments consisting of a string followed by zero to twenty variables. The string specifies how the command should use the rest of the arguments to construct a new string. Within the format string, percent signs are used to indicate special characters. The number of format specifiers in the string must match exactly the provided arguments
Some commands take a format string as a parameter. Format strings are actually a collection of arguments consisting of a string followed by zero to twenty variables. The string specifies how the command should use the rest of the arguments to construct a new string. Within the format string, percent signs are used to indicate special characters. The number of format specifiers in the string must match exactly the provided arguments


Line 73: Line 76:
'''%i''' - Prints the formID of the specified reference or object. GOTCHA : if a refVar is passed which points to a ref not loaded in memory %i will print 00000000 ''even if the refVar is not empty''.
'''%i''' - Prints the formID of the specified reference or object. GOTCHA : if a refVar is passed which points to a ref not loaded in memory %i will print 00000000 ''even if the refVar is not empty''.


'''%k''' - Prints the name of the key for the specified DirectInput scancode.
'''%k''' - Prints the name of the key for the specified [[IsKeyPressed|DirectInput]] scancode.


'''%n''' - Prints the name of the specified reference or object.
'''%n''' - Prints the name of the specified reference or object.
Line 101: Line 104:
</pre>
</pre>


==NVSE Alternative To Formatting==
As an alternative to string formatting, with NVSE functions such as [[Print]], you can use string concatanation and the [[ToString|ToString($)]] function.
<pre>
int iVal
ref rActor
PrintToConsole "Value of iVal is %g and name of rActor is %n" iVal, rActor
; can instead be written as:
Print "Value of iVal is " + $iVal + " and name of rActor is " + $rActor
</pre>
See the [[Tutorial: String Variables|tutorial on string variables]] for more information.
==See Also==
==See Also==
*[[ShowMessage]]
*[[ShowMessage]]
*[[MessageEx]], [[MessageBoxEx]]
*[[MessageEx]], [[MessageBoxEx]]
*[[PrintToConsole]], [[DebugPrint]], [[Print]]
*[[PrintToConsole]], [[DebugPrint]]
*[[String Variable]]
*[[String Variable]], [[Print]]
[[Category:NVSE]]
[[Category:NVSE]]
[[Category:String Variables]]
[[Category:String Variables]]
Anonymous user