2017년 6월 14일 수요일

Game Crashing: Can't figure out why


I am experiencing a problem and I cannot figure out why my app is crashing. On start-up the player is supposed to fling the multiplication sign at the two multiples upon the completion of that task the player will fling the equals sign at the product. (I will add directions for the game later once I get it working properly.) The game works fine until the score gets to 10-ish...then it crashes. If you restart the game after the crash you can play it once again. When the player gets to a score of 20 it is supposed to go to level 2. On this level the player moves the 'book shooter' into position and upon 'touch up' of the book shooter a multiplication sign is shot. The player must shoot the two multiples with the multiplication sign, then the equals sign is enabled and the player must shoot the product with the equals sign. This level crashes upon answering the first question.

I am stuck. (I did save an older version of the aia file before I added level 2. I hate to lose all of the work that I did though in adding level 2--1000+ blocks.)

Hopefully one of you can help me see what is wrong with an easy fix! <<fingers crossed>>


--
Just a first look.  Obviously nice graphics (well done).  Unfortunate they are not totally working the way you expect.


notice the duplication (red outline) ..

Do you know how to use the elseif blocks?   Your conditional construction can work however one of the MIT guys recently pointed out there is a huge 
efficiency is using  if then else if     rather than stacked  if then blocks.

I stalled out running this on Companion at a Score of 3 then the thing froze.

I might have suggestions tomorrow when I have more time.  Certainly others are looking at this too and will provide some feedback.

Your aia is 5.3 Mb.   Isn't the maximum size for the aia supposed to be 5.0 MB ?  You have several mp3 files over 1 MB each ..these 
can be made smaller.   Temporarily you might  delete them and see if you get better performance...be careful you have to also change the code in the places you reference them.

Gotta' run.

-- 
Thank you. After messing around with the code for hours, I am appreciative of a second set of eyes on this. I have decided to get rid of the music as I couldn't get it to run continuously through screen changes. I will delete the MP3 files entirely and see if that helps. I was wondering if I did the 'screen close' properly and if that could be the cause of the error. I will keep playing with it as well. Looking forward to your thoughts when you get a chance.

-- 
With your input above I was able to eliminate the MP3 files and correct the repeated 'if/then' statement you found AND it is working! I would like to add interest to the second level, however. I have already saved this working aia file to my pc just in case! I will be sure to heed your warning about file size under 5mb....I was unaware of this criteria. 

Thank you so much for your continued efforts in helping me!

-- 
Well, I thought it was working. I have played it several times after my original post above and it has crashed at various times. I have attached the modified aia file. (sadly named 'working'. lol) Any advice is appreciated.


-- 
" crashed at various times. "----ever get an error message?   What is going on when you elicit a crash?  Fling something, closing a screen, adding to your scores...

As mentioned previously   ifthenelseif    is more efficient and less prone to crash than   ifthen  ifthen   ifthen ...

Consider changing all  those separate ifthen blocks to  a ifthenelseif pattern. Changing the way you use the conditional probably will help.

You can do your app using a single screen.  A quick inspection shows the code in  Game1 and Game2 is nearly identical and could use the same Canvas on  a single screen.

The images currently on  Screen1 and TryAnother could be placed in vertical layouts on the GAME screen and hidden with Visible to false  and Visible to true., the Canvas etc. could be within another layout that turns on after you hide the current screen1/tryAnother stuff  ...why would 
I go for a single screen? ...because when you Close and change screens, sometimes unpredictable things happen.

I may look at this later if I have time.   You are going to have to do some debugging.  Do you know how to use  DoIt ?    If you crash while using Companion you can check the values that may have elicited the crash.

-- 
Yes, I was hoping that the 'if/then' statements were not the problem.I will work on this today and keep my fingers crossed. I am learning so much, but there is much more to be learned, I suppose.

-- 
Are there any shortcut keys that work with adding the 'else/if' statements? 

-- 
I've attached a Downloaded Blocks Image of your Game1 blocks.

You can usually tell from the shape of the block groups if the programmer has
been using lists effectively.

The long ladder shape can be replaced with list lookups
into three separate lists of sprites:
Ones_sprites(0...9),
Tens_sprites(0...9),
Hundreds_sprites(0...9),
using lookup in pairs blocks.

You would also benefit from a few value procedures
to extract the one, tens, and hundreds digits from a number...

ones_digit(n) = remainder of n divided by 10  (there is a math block for that)
tens_digit(n) =  ones_digit(floor(n/10))
hundreds_digit(n) = ones_digit(floor(n/100))


-- 
You are experiencing the problems of having lots of blocks.  Slow updating and movement on the Blocks screen and an issue with a mutator block getting large.

One solution:   break up the very tall  if..then ...else    into   several if then..else if blocks.

Second solution:  before you start, find out how many  else blocks are needed and add them unfilled, then fill them.

Third hint:    use the minus size on the lower right of the Blocks screen to reduce the blocks image while adding more  else if 

Sorry, this is ugly.

-- 
I needed to see if it could be done.  After 1/2 hour here is a condensed ifthenelse is now 5 procedures.   I will post the aia in a minute or two

-- 
Wow, thank you for the hard work. I appreciate your help so much. I was getting a bit frustrating in thinking that what I want to do is not possible. I stepped away for a few moments to get perspective and saw this.

-- 
So got back in and transferred all of the if/then/else blocks from the procedures right into the 'got.file1' block for both Game2 and Game1 screens and it worked! Game2 screen loads slow for the multiples and product, but game1 screen works beautifully. I will have to compare the code from Game1 to Game2 to see if I can find the reason why Game2 loads slowly. SteveJG, thank you so much. I would have never even tried modifying the if/then statements to if/then/else because I would have thought it wouldn't run any differently. I am so appreciative of your advice!

-- 
Great.    Other things that might make a difference:

Game2 Screen

1)  Your Delay procedure might be a major cause of whoa.   Here is why


In short, AI2 apps process information asynchronously..that means one command after another.  A procedure like you coded can cause processing interruptions.  Consider Scott's example as an alternative.
I notice you do not use a Delay block on Game1 screen.  Did you actually use your Delay procedure somewhere?

2) Your code in the Answer1, Answer2 and Answer3.click event handlers are essentially the same.  You could could the redundant pieces ... almost 100 blocks each into a Procedure and then call the Procedure in each of the buttons....   cutting down the numbers of blocks.

Game1
I did not check but similar issues as on the Game2 screen.

Make sure you save aia copies frequently ... you are making a lot of changes that are improving performance.  When developers get tired, we tend to make mistakes that are sometimes difficult if not impossible to back out of. Save often.

-- 
Tried combining the Answer1, Answer2, Answer3 repeated operations into procedures for correct and incorrect answers and it began crashing again. I also eliminated the delay procedure, which wasn't being used anyway.




-- 
I am not sure what is going on, the MultiplicationTriads (5).aia   loads but the screens display only after an excruciating wait.  Your previous aia loaded OK and ran with some issues.  You did not use the Ifthenelseif construction .
Is the file you attached what you intended.   You said you eliminated the delay procedure, however, this aia still contains the delay procedure blocks.

Regarding the time to load and display the game screens:
Game1 has 52 sprites
Game2 has 48 sprites

For the most part, your sprite sizing is  w = Automatic and h = Automatic.  This means AI2 has to calculate the h x w for each sprite.  This takes a small amount of time x's  about 50.  If all your sprites were 
right sized (used the dimensions actually posted) and.the sprite is set to the actual dimensions of the image, I believe the updating would go faster.... eg. if sprite is 50 x 50 pixels, set h and w to 50 pixels for the sprite.  Having right sized sprites  should give you a speed up.  For example number1.png is 26x38, number5.png is 26 x 37   ... just set these hxw to 26 pixels by 37 

A larger issue is you are using and constantly refreshing 50 sprites in you code (or so it appears).  Your Canvas only has the following important sprites displayed on the Canvas

                                                    16

                                            2           8

                                                 x  =

at one time.  Assuming sprite 16 is Sprite1, 2 is Sprite 2, 8 is Sprite 8     you  only need five sprites  plus possibly a few more to display 'rewards' for a basic game.  Instead of refreshing ALL the sprites,
change the image.png   for   Sprite1, Sprite2 and Sprite3  and never need to hide them .   A fraction of the updates    Currently there are many sprites and  they are hide/shown only as programmed and  required.  Changing a spirte's state from Visible= true to false or even updating probably requires a graphic's screen change.   AI2s graphic's screen update is probably one of AI2s worst features...it is SLOW compared to screen updating on almost any other Android compiler so instead of having 50 sprites, use  a dozen or less and 'recycle' them by changing the sprite.picture  instead of hiding/showing.

You got the basics for a great game but it still needs to be optimized.

MIT's Evan just made a post w.r.t. screen changes and the overhead and delay that happens when massive updates of screen components take place...so  your multiple screens is another choke point.  When you close a screen, everything on  that screen disappears from memory so when you come back to the screen, the screen needs to be completely refreshed on entering the screen.  This wastes a lot of processing time.

I might try using some of my own suggestions on an app that only uses two screens if I can keep everything straight. :(  

I have some ideas too about your File1.Got .. I don't think you need to use the File like thaat and load the csv into a List every time a screen loads.  I don't have that figured out yet.

-- 
Will reply more later. On the right track now. I figured out that the problem was the way I closed the screen and reopened it to 'reset' the game play for each 'level'. (You are VERY correct in your advice above.) I have now restored the 'if/then/else' statements (as per your earlier advice) and am working on consolidating repeated procedures. Thank you for your continued support. I sure hope that this thread helps someone else. I will have to think of a way to post my learning here so someone else can benefit. Will post again when I am finished. Thank you again!!!

-- 
The biggest lesson that I learned is that you cannot 'close screen' and reopen it to 'reload' the game...especially if you have a lot of image files and data to be recalled. This way will eventually cause the game to crash. You MUST put your 'reload' images and data recall into procedures. I now have a need for a 'wait' procedure after correct and incorrect answers to allow time for the player to see the "Great Job" and "Nice Try" pics...but I will research and if necessary post on another thread. Thank you so much, Steve, for your help! I was about to give up...but knowing that you were helping kept me trying for a solution!

-- 
Great news.  Keep at it.

wait procedure...a bad idea; you wantd a Clock.timer  to turn on the rewards/regrets  for a specific period of time, then to turn off the clock,

You need a Clock set with an IntervalTime of about 20 seconds.  The clock should initially be Enabled=false,  Easy to set on the Designer screen.  Remember the time units are ms    1 sec = 1000 ms.

after a correct answer for example,

display your image
followed by code to start the Clock:    Clock1.Enabled to true

In the Clock1.Timer event handler you write code to
hide your image and go to the next place.

then Clock1.Enabled = false   to turn off the clock.

Glad you can simile and continue with your project.  -- I guess this means you are no longer crashing :)

-- 
Yes. No longer crashing....AND your clock.timer idea is perfect. Works BEAUTIFULLY. Found a short tutorial on YouTube to guide me through your idea. I am very pleased with the way this is working out and I am sure that this will be a much more fun way to practice multiplication facts for my students! 

SMS to oneself - Automatic texting doesn't work


When doing an app similar to "No texting while driving", I tried sending an SMS to myself. Obviously, the automatic texting (WhenTexting.MessageReceived) doesn't fire in that case and I don't get an automatic answer when I text myself (on the same phone).

I just don't figure out why ? Has anybody a technical explanation on why this wouldn't work ? Maybe a stupid question but I'm wondering ... I checked out similar subjects on the forum first but didn't find an answer to that specific case.


--

How To Attach Multiple Files to an Email


Hi all, as an start i want to share that this is my first post and my first experience with MIT App Inventor 2, I'm  really happy to be here but sadly i do not have any skill or experience on programming.

Straight to the business my project is based on Photo Booth App, the idea is to create an app that can take pictures from cam  (1 to 16 already functional), then to have the ability to select from canvas x amount of images (never more than 16) and  sent them by mail. At this point following the step by step  Photo Booth App tutorial i'm not able to send more than 1 picture, (and that's ok becouse it's contemplated into the original code) but need to improve this part to send more files on a single mail.

now thinking in 3 variables that i was not able to solve by myself.
1 - how to attach more than 1 file
2 - how to set up a size limit for outgoing mail.
3 - maybe an additional box to add "subject" into email

I really appreciate any help or assistence. 

--
1. use the Mail extension to send emails via SMTP without user interaction to several To, Cc or Bcc addresses, add several attachments and send in plain text or HTML format.

2. to reduce the size of images, you can use my image extension
Image Extension to do some basic image manipulation.

• crop.aia

the Image Metadata Extension to read the metadata of an image file also might be helpful to get the size of an image

3. see 1.

--
thanks for time, today i'll try it and later i'll post results :D 

--

search results for multiple files to share


no, you only can send 1 attachment. Taifun. Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.
Hi all, as an start i want to share that this is my first post and my first experience with MIT App Inventor 2, I'm really happy to be here but saddly i do not ... more than 1 picture, (and that's ok becouse it's contemplated into the original code) but need to improve this part to send more files on a single mail.
If app inventor projects could function as Google Drive files it would solve this problem and a bunch of others, plus it would pull a ton of people to app inventor. Paul and Eric, ... create that multiple browser restriction only when the multiple logins are accessing the same project. Implementing that turns ...
100 x 100 pixel images should be ok..however how large are the actual files and are these png or jpg. Some users use bmp and tiff etc and that ... You did not share blocks, so advice is a guess. Only you can determine how you want ...
I am trying to create app in which I type and save multiple files in one screen and the file name get stored in another screen. ... I used tinywebDB because i want to share that file with my friends who has that app.. that list i said.. i dont want to create while creating app.. after app creation when ever i create ...
The main thing is that when you are working on such a large project, you should export your aia files to your computer frequently. We'll be working on ... Regarding the multiple browsers, I only did that after the blocks vanished in order to see if they were still there on a different browser. I am currently ...
(where indentation and multiple lines are allowed but irrelevant). Every expression ... It's also easy to share and reuse any blocks code by converting it to text and then back to blocks later. Your #3: AI2 has a ... The XML format I've seen in the block ZIP files seems like it might help address this. 3) The GUI ...
Example: Picking files from the SD CardHere's an example that illustrates using a third-party application:AndExplorer from Lysesoft is an application ... Also, with multiple screen apps, you can pass and return lists as values rather than just text, and you can share values between the screens with TinyDB.
Please do consider, if you use multiple screens, you will have to pass data between them (perhaps a TinyDB) or , since other are sharing, you will ... Do what you are comfortable with and please, please make sure you save copies of your project(s) as you develop (aia files, saving as Checkpoints or ...
(If your list data is in a multiple tab spreadsheet, it is easy enough to create another spreadsheet and =importrange() then data you want). Then probably easiest ... Not experimented, but guessing this can be done with all manner of google apps documents and non native files too. The real sticking point ...
You did not share your blocks Penelope that show how you save the sound and text files to the TinyDB. Perhaps you ... Are you using multiple tags?
Taifun,. Thanks, as always your answers are very helpful. My question was more like - how to share multiple files together. eg posting on facebook.
To ensure your safety, security, and privacy, never post your email address or any personal information you don't want to share with the world. ... Spam includes , but is not limited to, any promotional, commercial, or adult content, multiple instances of the same post, posts with URLs unrelated to the ...