Hello everyone, I have made a very big app that uses tons of code. Whenever I run the app, it works fine, but it usually crashes when I switch screens. Is this due to the amount of code or just because the app is glitching or another issue.
Brady, I strongly advise the use of Virtual Screens. That will stop the screen crash issue and improve on lag. The reason this is so is that Screens are separate allocations of memory (you could think of them as separate Apps as they don't 'know' each other exist). Virtual Screens however share the same memory allocation:
When we define virtual screens, we use one 'real' App Inventor Screen (most often Screen1). Screen-sized Vertical Arrangements on it are displayed/hidden as required - they are the Virtual Screens. This is generally a better approach for multi-screen Apps, they share data without having to "pass" it between screens and it also reduces code duplication, making the App more efficient and the code easier to follow if you have to return to it at a later date. So, instead of separate "houses", virtual screens are "rooms" of the same "house".
How to capture your Blocks to upload to the Forum:
Here are blocks for 1 screen which has the most blocks out of my whole app if you want other screens let me know.
(For some reason it won't let me make the image any bigger so sorry if its small).
@ChrisWard, I have used that method on other apps, however, it would be very hard and difficult as I already have a working app that I have been working on for a while. I get that method does work and probably has less lag because it doesn't have to load more screens with lots of blocks. It would just be easier if there was an easy fix to make it less laggy and not crash when it switches screens because even though there are lots of blocks, it is a pretty simple app.
That would take a lot of time! Click the image to preview, and click it again/scroll to zoom in. The main part is to remove unused parts, and correctly switching screens.
The redundancy, spotted by Gordon_Lu. Something else to notice first about that Block is that you should not need eight Clock Timers. You also do not need four Notifiers. These can be recycled.
Note how I have named the image sprite - this is good practice, you will always know what you are looking at if everything is named accordingly. Plus, when you need help on the forum, we need this level to understand your code.
One clear reason for crashing @ screen switch is that the Clock Timers are still running - they must be disabled. Of course, that's not an issue when switching Virtual Screens
Did you read this in an earlier post? My experience with Clocks is some applications need one or several to accomplish a goal. If you use multiple Clocks, ensure that the TimerInterval of the multiple Clocks are each set to different values. For example, if Clock1 fires at 1000 ms, Clock2 should fire at a different value, perhaps 1029 ms. Staggering will help avoid (but not eliminate) collisions (instances when both Clocks fire more or less simultaneously, creating issues). Experiment.
Sluggish? Experiment with different TimerInterval settings. What values; sorry I don’t know. What values do you use in the Clock TimerIntervals? Are they staggered?
changing Screens (Chris already mentioned this) Before you change (if you must use real Screens) make sure in the Properties AlwaysFires is unchecked (disabled).
graphics and redisplaying a screen is one of the worst features of App inventor. AI's graphics are notoriously slow compared to Java and JavaScript based games. AI is not a game engine although some fairly good games can be made.
Notifiers. Are they set for long or short duration. Another time waster. Posting to a Label is faster and in some cases a nicer way to provide game info. If you must use them use short duration.
Luck getting rid of your lag. The more sprites, the larger the original graphic image slows your app because the app has to process downsizing the image,
Lagging is a problem with graphic games on App Inventor. The lag can be ameliorated. Hope you find your gremlins. The above list is not exhaustive.
@gordonlu310 thanks for that info, I will try those things you said to make the code shorter and easier.
@ChrisWard, I have 6 screens.
Screen 1: Just has 1 start button and a logo to enter the app.
Screen 2: Lets you pick different levels to play on.
Screen 3, 4, 5: All different levels to play on, one is easy level, one is medium level, one is a hard level.
Screen 6: Credits screen, they get to this after they complete the game.
I will try what all of you said and get back to you, thanks for all your help!