@minecraft/server-ui / MessageFormResponse
Class: MessageFormResponse
Defined in: @minecraft/server-ui/index.d.ts:968
Returns data about the player results from a modal message form.
Examples
showBasicMessageForm.ts
typescript
import { world, DimensionLocation } from '@minecraft/server';
import { MessageFormResponse, MessageFormData } from '@minecraft/server-ui';
function showBasicMessageForm(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
const players = world.getPlayers();
const messageForm = new MessageFormData()
.title('Message Form Example')
.body('This shows a simple example using §o§7MessageFormData§r.')
.button1('Button 1')
.button2('Button 2');
messageForm
.show(players[0])
.then((formData: MessageFormResponse) => {
// player canceled the form, or another dialog was up and open.
if (formData.canceled || formData.selection === undefined) {
return;
}
log(`You selected ${formData.selection === 0 ? 'Button 1' : 'Button 2'}`);
})
.catch((error: Error) => {
log('Failed to show form: ' + error);
return -1;
});
}showTranslatedMessageForm.ts
typescript
import { world, DimensionLocation } from '@minecraft/server';
import { MessageFormResponse, MessageFormData } from '@minecraft/server-ui';
function showTranslatedMessageForm(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
const players = world.getPlayers();
const messageForm = new MessageFormData()
.title({ translate: 'permissions.removeplayer' })
.body({ translate: 'accessibility.list.or.two', with: ['Player 1', 'Player 2'] })
.button1('Player 1')
.button2('Player 2');
messageForm
.show(players[0])
.then((formData: MessageFormResponse) => {
// player canceled the form, or another dialog was up and open.
if (formData.canceled || formData.selection === undefined) {
return;
}
log(`You selected ${formData.selection === 0 ? 'Player 1' : 'Player 2'}`);
})
.catch((error: Error) => {
log('Failed to show form: ' + error);
return -1;
});
}Extends
Properties
cancelationReason?
readonlyoptionalcancelationReason?:FormCancelationReason
Defined in: @minecraft/server-ui/index.d.ts:659
Remarks
Contains additional details as to why a form was canceled.
Inherited from
FormResponse.cancelationReason
canceled
readonlycanceled:boolean
Defined in: @minecraft/server-ui/index.d.ts:666
Remarks
If true, the form was canceled by the player (e.g., they selected the pop-up X close button).
Inherited from
selection?
readonlyoptionalselection?:number
Defined in: @minecraft/server-ui/index.d.ts:975
Remarks
Returns the index of the button that was pushed.