[no fix] MessageBox, “Message”, [var1], [var2], [“button1”], [“button2”]
The MessageBox command lets you give out information to the player. Normally these appear as a small box with the text on the bottom of the screen that stays there for a few seconds or until the player has clicked a button if the message box has buttons. There is a limit of 9 buttons per message box. If a dialogue window is open, MessageBox will output to the dialogue window! This will be in a different color so it's a good way to show that text isn't part of dialog. For example, "Okay I'll take the curse off. He takes the curse off." MessageBox has several different modes of operation. The simplest one is just giving out an onscreen message that appears on the bottom of the screen for a few seconds, as in the following script that gives out a message when the item it’s attached to is equipped:
Begin informplayer
Short OnPCEquip
if ( MenuMode == 1 )
return
endif
if (OnPCEquip ==1 )
MessageBox, "The sword vibrates in your hand"
Set OnPCEquip to 0
Endif
End informplayer
The second mode of operation makes the message stay on the screen until the player presses a button:
MessageBox, "Ulyah lifts her hands and speaks the formula. You will now be transported to Sheogorad", "ok"
In the third mode of operation you can use the messagebox to demand a decision from the player via a message box with buttons and the GetButtonPressed function.
Warning: The use of more than one messagebox in a frame can cause a CTD. This also includes the “Your journal has been updated” messagebox.
Multiple MessageBox commands in the same frame can cause a crash. The problem doesn't seem to appear if you do 2 MessageBox commands in a row, but stick any other commands between them and you'll have problems. Using 3 simple messages in a row can work, but usually crashes if there are variable substitutions involved.
I'm guessing it's partially an interaction with the voice subtitle boxes. There may be some overall limit to the number of messages per frame. -(CDCooley)
Notes by DinkumThinkum:
1. My impression is that any type of text messages have the potential for triggering a crash if they're generated in the same frame.
2. The bug doesn't trigger a CTD every single time you generate two text messages in the same frame: it appears to be a random chance of it happening. But, from what I saw when I tested this: if you keep generating two or more text messages in the same frame (with some other code in between them), sooner or later you will crash. Sometimes my test script would cause a CTD within a few seconds, sometimes it would take five, ten, or more minutes, but it would invariably crash if I waited long enough.
3. For a start-up script I was working on when I ran into this, adding a one frame delay between popping up a Message Box message and updating the player's Journal eliminated intermittent start-up CTDs I had been getting.
There also appears to be a problem if you call too many message boxes from the same script, even if you set up a frame counter. I'm not sure the limit, but I discovered it when testing NecroRise a while ago... Apparently, 50 is too much. (Forum info / Cid88)
Note: If you use a Tribunal start script to give out a message box with a button as soon as the game is loaded, you should delay the MessageBox, otherwise the mouse pointer will not be displayed.
A one frame delay isn't enough if you have a massive start-up script that runs as soon as the game is loaded. So you might want to delay Message Boxes (that have buttons) for a second or so after the game is loaded, just to be on the safe side. (Forum info / DinkumThinkum).
If there is already a messagebox with choices on the screen, opening another choice messagebox will cause the first choice messagebox to vanish. However, when the player picks on of the choices, the messagebox vanishes and the crosshair appears but the player can’t move.
Using menutest, 0 will allow the player to move again.
You can enter carriage returns to message boxes, but it requires hex-editing the .esp. Put some unusual characters like ||, then save the esp. Then hex edit the || characters and make them 0D0A (hex for carriage return). (Forum info / qarl)
[no fix] GetButtonPressed (returns short)
Pressed button if a message box with buttons is used, starting at 0. Will return –1 until button is pressed.
Sample Script:
Begin choices
Short button
Short status
Short OnPCEquip ;declare as variable – otherwise there will be errors
if ( OnPCEquip ==1 )
MessageBox, "The sword vibrates in your hand. Do you want to equip it?", "yes", "no"
Set OnPCEquip to 0 ;display the Message Box only once
Set status to 1
Endif
If ( status == 1); wait for player decision
Set button to GetButtonPressed
If ( button == -1 ); no button selected yet: do nothing
return
Elseif ( button == 0 ); continue normally
Set status to 0 ; reset for next time
Elseif ( button == 1 )
Player->drop, "power_sword" ; makes the player drop the item
Set status to 0
Endif
Endif
End