How do I change screen once there are 0 lives in game app?

Hi. What can I do if I want (for example) that if the player reached 0 lives, it will go to another screen? And if they didn't reached 0 lives they will still go to another screen but for victory? Here are my blocks:

Thanks.

Hi

Looks like it doesn't have to literally go to another Screen, just re-use the current Screen? Difficult for us to visualise your game with just those Blocks to study.

2 Likes

How can I do that? Anyways, here is the designer screen:

Hi.

We have been doing a game app in which the player should answer the given multiple choice questions correctly in order to heal a patient's body. If the player have made their lives meter 0, it will open to another screen that says they did not saved the patient. And also, when after finishing the questions but still have more than 0 lives left, they should also open to another screen but for victory. How can I create those? Thank you so much for those who will answer:) Here are my blocks and designer screen:

So the App will have a total of 3 screens in that scenario. I think you only need 1 Screen for the game and if you insist, a second screen to announce victory or defeat, depending on which is which. That can be decided in you "Game Over" Procedure.

On Screen 2, have two full-screen Vertical Arrangements, both set to 'visible false', one holding Victory information/graphics, one holding Loser information/graphics.

GameWonLost.aia (3.5 KB)

Screen1
blocksScreen1

Screen2
blocksScreen2

To return to Screen1, it is important to simply close Screen2 as shown. You could also provide a button to do the same.

1 Like

This discussion is a continuation of the discussion Add lives in quiz app

Change your Screen here

or follow Chris' advice.

Learn to use conditional IF statements Programming Your App to Make Decisions

1 Like

Hi. I tried your solution first. After adding editing the blocks in our game app, there was a runtime error as well as the timer and lives label in our app disappeared. What can I do to make it fixed? Here is our blocks and screen:

Sorry, I don't know. I assume you have a Screen called Wrong_S4 . It's been a long time since I worked with 'real' Screens...I think the under bar might not be allowed in the screenName but I do not remember. Check your spelling and case; you might rename the Screen WrongS4 and try again and you might avoid the runtime error.

Does the app switch to Wrong_S4 at all or do you get a runtime error without switching?
The timer and the lives label disappeared...does Wrong_S4 duplicate Screen1 graphics? When a developer uses real Screens and switch to them, the screens are stupid. You must 'refresh' the information displayed in the Wrong_S4.Initialize Block. That might be why you do not see the clock and the lives label. I can only guess, not being able to test. When you use a real Screen you are actually running a separate sub app.

You could avoid this by using virtual screens ... Building Apps with Many Screens where you do not actually move from Screen1 but use layouts to display virtual screens.

Show the runtime error (screenshot) and show also the screen Wrong_4S.Initialize block. Switching to a screen named "Wrong_S4" shouldn't be a problem.
To make it easier, also post the aia or a test aia that reproduces the problem.

Here is the aia file of our app:

Sorry it is in a google drive file. Apparently it exceeded in the uploading limit.

Also, the screen names that is important is the 'questions' and screen8 screens...

It switches to Wrong_S4 and it also has a runtime errorScreenshot (60)
If I connected it for the first time from my ai companion, there is still the timer and lives but when it went from Wrong_S4 to the 'question' screen(which is where the quiz is), the lives and timer are gone.

You're switching screens wrongly. All screens are opened multiple times, which leads to a memory problem. You must close each screen (except Screen1) when opening a new screen.

grafik

To get back from a screen to Screen1 just close this screen.

Otherwise the app seems to run without any problems (on Android 9) .

If you are running your app on iOS (MIT App Inventor for iOS), you should have communicated this beforehand and created the topic there.

Is there an issue with the mit app inventor in ios? Because I have no android phone and that my laptop cannot download an emulator.

And also, what can I do when all the questions have been answered but there is still lives left? I wanted it to change the screen into a victory screen however stevejg and chris ward's solutions wasn't working for me

Yes, there may be an issue in ios. Anke indicates your app seems to run ok on an Android 9. The error message you get with the word 'Irritants' frequently happens when the current version of ios trips a bug. That you switch to Wrong_S4 is a good sign that the screen changing Blocks work. The app, as is works on an Android 8.tablet. A problem is the Lives never get to 0 so switching does not occur (the aia you provided does not have your Screen switching Blocks).

Your code should work OK as you posted on an Android. Anke's 'correction' shows a way to change screens and avoid system memory issues (and you should try that). If the app doesn't work after you modify; the issue is probably an iOS issue.

Why not? What happens when you download the emulator? Is your laptop a PC or a Mac? Perhaps we can help you get the emulator working.
Unfortunately your aia will not load into the stock emulator. I expect the emulator has insufficient memory to load your aia which is 16Mb. That is large and indicates your images are probably too large. Here is some advice:

  • Using Images with App Inventor
  • remove images (and files) you do not actually use in the app; those images are included in your app and you do not want that.
  • temporarily remove your large audio files; Doing that might let your app load in an emulator
  • your gifs and mp4 are probably issues
  • resize you large images. There is more resolution than can be displayed on most cell phones. For instance Screenshot 2001.... png is 0.9 mb. Your intro screen is huge.

Before changing screens, all timers in the current screen must be stopped - otherwise the App becomes corrupted.

We've filed an issue on our internal bug tracker to investigate why you're getting a null reference.

Also, it appears as though the project is corrupted in some way. There is a Screen2 that is present in the file, but its design file is completely empty (there's always a bit of metadata, so this is odd). We'll probably need to clean up the project a bit first before investigating further.

1 Like

In this link, when I click the 'download the installer' nothing seems to be happening. So I don't know why it can't be downloaded. I use a laptop PC
https://appinventor.mit.edu/explore/ai2/windows