How can I make my lamp indicator color turn green once it reaches a certain number with the app.label.Text

조회 수: 4 (최근 30일)
I'm making an app thats whack a mole, and for my app i want to do different levels, with each level the objects move faster. I'm trying to make it where in each level theres a lamp indicator that turns green after a certain amount of points is aquired. I'm using buttons for my objects moving, Label text as where the points get shown growing, but everytime I make a loop or some formof code with the lamp, it'll just stay red.
I tried using
if app.Label.Text<500
app.Lamp.Color='r'
else
app.Lamp.Color='g'
end
and it stays red because I thin once you start the game it just recognizes the app.Label.Text already under 500 and keeps it red after 500.
  댓글 수: 1
VBBV
VBBV 2023년 4월 25일
편집: VBBV 2023년 4월 25일
Note that if-else is a conditional statement not a loop. it will execute only ONCE if the condition is NOT present inside any loop (e.g. while or for). So once the condition is executed, it will never change the values of variables again unless present inside the loop. From your code its apparent that the condition is NOT INSIDE any loop. Try with a loop instead.

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

답변 (1개)

chicken vector
chicken vector 2023년 4월 25일
uilabel dont allow much interactivity.
I guess you have some familiarity with Callbacks, so I suggest you to use uieditfield and have a look at:
@EditFieldValueChanging
This callbacks triggers a function every time the text inside the EditField is changed.
Then you can insert your length check inside that.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by