Problem happened in making xylophone (record & playback)

Hi! Today I want to make a xylophone recording and playing back notes. I know there is one tutorial in App Inventor, but I want to use my own coding instead. I will use another alternative way to store a song.
Here are the instructions: Xylophone Advanced.pdf (324.4 KB)
The assignment is proved difficult and I even don't know how to do it.
For the designer part:


I'll set some variables to do the process: lastPair, lastTime, song.
When I press any of the buttons, it will make a sound corresponding to the note.
The variables and procedures of the code:
Xylophone Variables & Procedures
Step 1 of the code: (I have no problem for that currently)

Step 2 of the code: (when one of the note buttons click, what will happen?)

Step 3 of the code: (most confusing :frowning: )

Here are all the codes that I have made.
But when I tested the app, it has a runtime error showing that the index originally need to change to 1 but the length of the list is 0...
Also, I cannot record or playback any of the notes, which is the most concerning for me.
It is complicated, and I don't know how to solve the problem or finish the app in success.
Thus, please help me or give me some advice! Thank you!

Please look at the instructions before replying to this post or otherwise you won't understand what's going on now. Thank you so much!

See here:

https://groups.google.com/g/mitappinventortest/c/Iu-tiC9GWgk/m/Xw3wdzFUBgAJ

Thank you for the link! However, I'm trying not following the instructions of App Inventor as I have it on my own. I want to have another alternative way to record and playback the song.

You need to debug this; impossible without the aia and guessing at the cause only by inspection. Use DoIt (see Enis's advice at http://twodogapps.com/?page_id=686#DoIt ) What is apparently happening (a guess) is you attempt to use a List before the List is actually populated. The problem might be how you use your Clock. The order of the blocks in your PlayBackNote Procedure are also suspect. Your sound.source possibly should be in the if statement to prevent selecting a source inadvertently.

Also figure 15-5 in http://www.appinventor.org/bookChapters/chapter15.pdf may help you debug.

Keep on experimenting. :slight_smile: Realize, no one can test your app without an aia so you have to debug it.

  • From your blocks the if-statement is never true
  • global var lastTime is set to false and this cannot be used in a duration block

Tysm! I will try to improvise the coding of the project using your suggestion!

Hello everyone! I've tried to improvise the project by correcting a few codes. Here is the project I have made with your suggestions.

  1. The variable last_time is changed to an invalid value initially. When the user presses the other button, the variable will change.
  2. I have corrected a few mistakes in the playback and timer section.

Here is the project attached:
Xylophone.aia (593.1 KB)
Please don't change it :slight_smile: Reply to this message if you have any comments on this! Tysm!

However, there are a few things I'm concerned about. Firstly, when I tested the project in the AI companion, it shows that there is a 701 and 703 error (Unable to load/Unable to play). Why is this happening? Thanks.

Read this first (especially point 3 and 4):