How do I force a screen update before the end of a function?

Hi, I'm new to MIT App Inventor, so this may not be surprising, but after looking for answers (and turning up with nothing) I figured I'd come here.

Currently I'm working on an app that will be used to help score ping-pong matches. Each time the referee presses a button (up or down) it updates the value of the team's score [current round 0 - 11 (if lead by 2 pnts, else continue until having a 2 pnt lead) and round score (0 - however many rounds you play)]. This part works.

What doesn't work is that I can't force the screen to update the text values before finishing the tasks in the button click block. Ideally I want the main score P1/P2 to visually update (after the call to dsp_txt) when the user presses the button, then continue to check if the round has ended (post-dsp_txt), if it has then it will update the score for the round via T1/T2.

Is there any way I can update those values before the block inside the button click function completes all of it's tasks? Any help would be much appreciated, thanks in advance. :slight_smile:


Welcome Aiden.

App Inventor is single threaded so you can't do that.. App Inventor processes commands asynchronously, so one command must execute before the next executes. See The model of event processing in App Inventor by Franklyn_A_Turbak

Thanks for the quick response SteveJG, I guess I have just one follow-up question before I re-design my app concept.

Since my screen won't update until the event handler is finished processing, would there be a way to put the display text functions in a separate procedure that could be called with a boolean outside of any button clicks?

if that sounds confusing: button clicked; variables updates; updateScreen = true; button clicked event finished; goto procedure updateScreen; display text associated with the variables;

I do not understand your logic. Sorry. You might get the behavior you expect with something like this

by re-ordering your Blocks
at a guess.

You don't show all your Blocks (only you know what happens behind the scenes) so other techniques might be necessary using the Clock's event handler to 'schedule' events. This needs to be experimented with using your code and trying different things. :cry: So experiment. You might be able to use the break Block or a while control Block(s).

Each variable I have in this program is initialized to 0 or in case of a string "". Not sure if this helps (I totally get it that it looks confusing)

Is a while loop (with or without breaks) considered an event or does it just exist and execute commands?

Now it is possible to see some of the issues you are facing.

Are either of these ideas your panacea? Probably not but knowing about these methods might help you solve your issue.

Looks like this might lead towards a solution or a least a good re-adjustment of my objective :slight_smile:

I'll be going to my classes soon so I'll be away from the forum for a while, but thank you so much for the resources you've provided, I'll be sure to read them and get back to you on what I find.

Ok, so I had some time to read those articles, and yeh, as you predicted they didn't quite solve my problem, but they did lead to a more solid path moving forward. Thanks so much for the help :slight_smile:

I'll keep probing around for better ways to organize my code. Hopefully it works out in the end.