×
Меню
Индекс

MSFD Displaying variables and text defines in a message box

 
To display variables in a message box you need to use a syntax describing the format of the number to be displayed. ATTENTION – there is a lot of wrong info in the original helpfile on this!
 
MessageBox "You have %.0f days left", days_left
 
The % symbol indicates the variable. The number after the dot determines the number of digits displayed. "f" signifies a float variable. The helpfile lists several types (f for float, D for short or long and S for string variables), of these I could only get f to work. However %g and %G work fine for short and long variables (thanks Niyt Owl). You can use things like %.3g, but the digit designation will simply be ignored. The designators are not really specific to the variable type, %.3f will also display a short or long variable. There is a limit of 9 variables that can be displayed in the same messagebox (though for some reason the error message for exceeding this limit is "Max variables of 10 exceeded on line XXX").
String variables are mentioned in the helpfile but are to my knowledge not implemented, you can however use dialogue text defines in message boxes but do NOT use %: for text defines –In scripts it's ^instead (thanks Ragnar_GD):
 
Text defines:
^PCName     The player's name.
^PCClass     The player's class.
^PCRace     The player's race.
^PCRank     The player's rank in the speaker's faction.
^NextPCRank     The player's next rank in the speaker's faction.
 
^Cell          The cell the player is currently in.
^Global     Any global variable value. Floats display as 1.1, such as ^Gamehour
 
Note: you can also display a Global variable normally, using the above syntax such as %.1f, which would yield the same result. If you use the ^Global text define in a book, Morrowind will usually crash if you access or change the global variable while the book is open. This should be avoided at all costs! (Forum Info/Chris_K)
 
^Name          The speaker's name.
^Race          The speaker's race.
^Class     The speaker's class.
^Faction     The speaker's faction. If they have no faction, it will be blank.
^Rank          The speaker's rank.
 
Note: These last listed ones will not work quite as they do in dialogue, as the defines default to the PC's values by default, not to the calling Actor. So ^Name and ^PCName will both display the PC's name, even if the MessageBox is called from dialogue results.
 
Example Script: Stupid sample script demonstrating all possible syntax:
Begin test1
 
short var_1
long var_2
float var_3
; GameHour is a global float variable
 
set var_1 to 1
set var_2 to 2
set var_3 to 3
 
 
MessageBox "^PCName, you have %g head, %G hands, and %.5f gold. One could say the hour is getting late in ^cell. It's the ^GameHour hour or more exactly the %.2f hour!", var_1, var_2, var_3, GameHour
 
End