How do i get user input into msgbox

6 visualizaciones (últimos 30 días)
Joseph Kain
Joseph Kain el 29 de Feb. de 2016
Comentada: Joseph Kain el 29 de Feb. de 2016
So for my engineering project, I am creating a text based adventure because it sounds fun. So the first prompt players are greeted with is as follows:
playername = inputdlg('Welcome to The RPG, what is your name?:', 'RPG', 1);
charactername= playername{1};
msgbox(sprintf('Nice to meet you %g', charactername))
So the player is suppose to enter their name, and then I'd like the message box to restate their name, but when I run the code this happens "Nice to meet you98Nice to meet you 101Nice to meet you 110"
Any ideas?
  1 comentario
Joseph Kain
Joseph Kain el 29 de Feb. de 2016
I got it it, heres the code:
playername = inputdlg('Welcome to The RPG, what is your name?:', ' RPG', 1);
charactername= char(playername(1));
msgbox(sprintf('Nice to meet you %s\n', charactername))

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 29 de Feb. de 2016
%s not %g

Más respuestas (0)

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by