필터 지우기
필터 지우기

When I press next question, it doesn't go to the next question

조회 수: 1 (최근 30일)
Thomas
Thomas 2024년 3월 22일
답변: Ishu 2024년 4월 2일
I'm making a quiz-like game on the app designer section of matlab, where the user can select easy medium hard, which will display different flags for the user to select one of 3 options. I managed to get the first question to appear, but when I added the 'next question' button, the programme does not want to go the next question. Any help would be much appreciated
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
ReturnButton matlab.ui.control.Button
NextQuestionButton matlab.ui.control.Button
option3 matlab.ui.control.Button
option2 matlab.ui.control.Button
option1 matlab.ui.control.Button
Label matlab.ui.control.Label
Image matlab.ui.control.Image
Button3 matlab.ui.control.Button
Button2 matlab.ui.control.Button
TextToUser matlab.ui.control.Label
GeographyQuizLabel matlab.ui.control.Label
Button1 matlab.ui.control.Button
end
properties (Access = private)
Property % Description
counter = 1;
Difficulty = [1,2,3];
end
% Button pushed function: Button1
function Button1Pushed(app, event)
% starts easy games
app.Difficulty = 1;
app.counter = app.counter+1;
app.Label.Text = "What is the country seen below?";
app.Button1.Visible = "off";
app.Button2.Visible = "off";
app.Button3.Visible = "off";
app.TextToUser.Text = "";
app.option1.Visible = "on";
app.option2.Visible = "on";
app.option3.Visible = "on";
app.Image.Visible = "on";
if app.counter == 2
app.Image.ImageSource = "italyFlag.svg.png";
app.option1.Text = "Italy";
app.option2.Text = "France";
app.option3.Text = "Spain";
end
% Button pushed function: NextQuestionButton % The counter should increase by 1 when the next
function NextQuestionButtonPushed(app, event)
app.counter = app.counter + 1;
if app.Difficulty == 1 && app.counter == 3
app.Image.ImageSource = "RomaniaFlag.png";
app.option1.Text = "Chad";
app.option2.Text = "Bolivia";
app.option3.Text = "Romania";
end
  댓글 수: 1
Walter Roberson
Walter Roberson 2024년 3월 22일
Your functions Button1Pushed and NextQuestionButtonPushed are not configured as button pushed callbacks. The functions exist but there is no way to get to them.

댓글을 달려면 로그인하십시오.

답변 (1개)

Ishu
Ishu 2024년 4월 2일
Hi Thomas,
I understand that you are not able to go to next question when you press the "next" button and I am assuming that the functionality of your next button is defined by "NextQuestionButtonPushed" function.
This can be due to the possibility that there may be no callback to the "NextQuestionButtonPushed" function so your next button is not behaving as expected. You can add the callback to these functions in the "startUpFcn" callback to the UIFigure.
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
% "Next" button creating code
app.SubmitButton.ButtonPushedFcn = createCallbackFcn(app, @NextQuestionButtonPushed, true);
%Similarly you can add callback to "Button1Pushed" also
app.SubmitButton.ButtonPushedFcn = createCallbackFcn(app, @Button1Pushed, true);
end
end
You can add callbacks according to the behaviour of your code.
For more information you can refer below documentation:
Hope it helps.

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

태그

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by