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

2 Ansichten (letzte 30 Tage)
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 Kommentar
VBBV
VBBV am 25 Apr. 2023
Bearbeitet: VBBV am 25 Apr. 2023
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

chicken vector
chicken vector am 25 Apr. 2023
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.

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by