2016년 12월 5일 월요일

Using a get to get the last component called in a list


A part of what i'm making involves having a button which, when clicked, plays a random sound from a list of sound files. I did this by creating a list and inserting the sounds into the list. Let's say there's 3 sounds - cow, pig and chicken.  

What I want to happen now is when I click the button and hear the animal sound, I need to click the correspondent button.  

So far what I have is this - http://i.imgur.com/4xxI7KE.png.


First two blocks create the list, the second group of blocks insert the sounds into the list and the third group of blocks is a fragment of what i'm trying to find out now. In normal programming i'd just create a variable and save whichever sound was played onto that variable, and then use an "if{} else if{} else{}" and use gets to get the value of the variable, though with MIT App Inventori'm not sure how I can get it to know which was the last sound that was played.

-- 
use the random integer block instead of the pick a random item block, see this example https://puravidaapps.com/snippets.php#2removerandom
removerandom.aia
share.aia


-- 
I want them to remain in the list though. I click the Randomize button and hear, let's say a dog, click the button for the dog and it'll say whether i'm right or wrong.
Then I click the Randomize button again and it has a chance of any of the 3 showing up again.

-- 
use the random integer block as already mentioned and adjust the provided example to your needs

-- 
Finally got it!

If you wanna see how it turned out then: http://i.imgur.com/thfccrH.png

I used the randomsound component linked to the randomize button, left it blank, changed it's source to whichever file was randomly pulled from the list and did my "if{} else if{} else{}" comparisons based on the current randomsound source.

-- 
next time please include screenshots directly into your thread instead of only a link to another server. thank you.
 screenshot.png

-- 

Android Directory Structure


I am now working with Taifun's FTP extension, and understand the general workings of it, particularly the remote server side aspects. I have used Taifun's example app and it works with no problems.

My problem is that I don't quite understand the Android Directory Structure. For instance if I create a TinyDb with tags, what is the absolute path to that TinyDB?

From that TinyDb I can create a .csv file for uploading, in Taifun's extension, what would be the local directory for that file?

Whilst researching for an answer myself, I found that AppInventor has created a directory on my phone with two subdirectories, Assets and Data. Are these directories used only whilst in development?

-- 
TinyDB is an xml file and that file is accessible only on rooted phones


I found that AppInventor has created a directory on my phone with two subdirectories, Assets and Data. Are these directories used only whilst in development?

yes

-- 
I want to upload a .csv file which I have created from a TinyDb. Using your FTP extension, could you explain where  the .csv is located?

I also want to download that same .csv into another app. What is the path to that local directory to download into?

I know these seem like the most basic questions to you, but as stated in my first post, I am unfamiliar with Android file system...

-- 
I want to upload a .csv file which I have created from a TinyDb.
how did you create the csv file? Using the file component?

Using your FTP extension, could you explain where  the .csv is located?

assuming you are using the File.SaveFile method, you define the path to the file yourself, just use the same path for the ftp extension


SaveFile(text text, text fileName)
Saves text to a file. If the filename begins with a slash (/) the file is written to the sdcard (for example, writing to /myFile.txt will write the file to /sdcard/myFile.txt). If the filename does not start with a slash, it will be written in the program's private data directory where it will not be accessible to other programs on the phone. There is a special exception for the AI Companion where these files are written to /sdcard/AppInventor/data to facilitate debugging. Note that this block will overwrite a file if it already exists. If you want to add content to a file use the append block.



I also want to download that same .csv into another app. What is the path to that local directory to download into?
what is the local directory you are talking about?

the ftp extension can only store files on sdcard, see also the documentation https://puravidaapps.com/ftp.php
Download one or all files from remote directory into local directory on SD card.
In case the local directory does not exist, it will be created. If the localDirectoryName starts with file:/// you can specify a complete path for example to download to the external SD card.
To download all files from a remote directory, use an empty string as remoteFileName.

-- 


help needed! Quiz app


I need to create a quiz app with questions (taken from a lits of 3000 questions) and answers in 4 options with different points if you get the right answer or not answer at all, with a maximum total time for completing the series of 60 questions every time you start the game.
Someone can help me?

-- 

A Multiple Choice Quiz: How to work with the advanced features

☞ quiz.aia


--

Still Having ftp trouble


From the blocks below in a test app, you can see that I am usung Taifun's FTP ext. I can save a file, I can read from that file into a label, but when I try to upload it, I get an error saying that the file does not exist. Could anyone inform me as to what is wrong?

Although the blocks at the moment do not show it, I have also prefixed the join part of the upload with file:// ; and it still doesn't help...



Thanks in Advance

-- 
use Do it to debug your blocks, see also tip 4 here

and use the correct path to the file, see also the documentation https://puravidaapps.com/ftp.php

Prefix the filename with / (i.e. relative path) to upload a file from the SD card. For instance /myFile.txt will upload the file /mnt/sdcard/myFile.txt. To upload assets packaged with an application does not make sense and has been disabled therefore. If a fileName starts with file:/// you can specify a complete path to the file. 
      


-- 
also you first should set the correct parameter and then do the upload
-- 
I managed to do it. Taifun's cryptic help made me look harder, and after nearly two weeks of trying, I finally got it... and I won't forget it now...

-- 
Taifun, the way I had it worked. The only thing I changed was when I was joining in the save file, I added another text block in it with /, and it worked. Although I guess I should move the call ftp up and call it before the file name as in your last example. Thanks...

-- 

Taifun's cryptic help made me look harder, and after nearly two weeks of trying, I finally got it..

???
what kind of help is easier to understand for you? any suggestion?


 The only thing I changed was when I was joining in the save file, I added another text block in it with /

yes, you have to use the correct path to get it working and to find it out, "Do it" is the way to debug your blocks ...

-- 

Constantly changing score keeper


I want to create an app that keeps score with objects constantly getting new points. Like this:

When Round one is done: A = 0 point, B = 1 points C = 2 points

Score:
C
B
A

When Round two is done: A = 1 point, B = 2 points, C = 0 points

B
C
A

Etc... So the letters keeps the points, and the scoreboard changes. Is there an tutorial app that does something like this, that I can build?

-- 
You can find that under the search term HIGH SCORE in this board.

-- 
No, not a high score... A score keeper or a score board.

--
Try this ...


--
Thank you! I will try it

--

Well, I tried that and I have come that far myself. What I want is a scoreboard that when something gets more points, it rises in the score. That is what I can't figure out. 

-- 
At this point, I am assuming you have a list of lists (a table),
with each row containing (name, score) and
they are stored in descending score order,
with the row with the highest score at position 1.

I also assume you have a stopper row with score 0 at the end, to make things easy on you.

This two column table can be used as a lookup table using the
lookup-in-pairs block, to tell you what score is in the table for a given name.

Say your new score is in global variable NewScore, for name PlayerName.
You want to see if PlayerName beat his old score, or if he is a new player.

If lookup-in-pairs(ScoreTable, PlayerName, default=0) < NewScore THEN
    (We want to clear any old score for that player, then insert his new score in the right place)
   For Index = length(ScoresTable) to 1 by -1
      If Select item 1 of (Select item Index of ScoreTable) = PlayerName THEN
          Remove item Index from list ScoreTable
   (end For loop)
   (old score cleared, now look for right place to insert new score)
  Set global InsertionPoint to 1
  While (select item 2 from (select item InsertionPoint from ScoreTable)) > NewScore 
     Set global InsertionPoint to InsertionPoint + 1
  (end While)
  (We have skipped past all the higher scores)
  Insert (make a list(PlayerName, NewScore)) at position insertionPoint in list ScoreTable
end If

-- 
Thank you, this seems to be what I'm looking for.

-- 

FTP client


Is there no Free example of an FTP client application?

-- 

there is my ftp extension available for a small fee here http://puravidaapps.com/ftp.php

and for a small monthly fee there is the Silver Plan of AppyBuilder, which offers a ftp manager component
and you could write your own ftp extension yourself and provide it for free for the App Inventor community...

more information about how to create an extension see the App Inventor Extensions
however that will be more advanced and will require some Java skills...

-- 
To write a Java extension to FTP with AI2  you will need some Java code.   Here is a link to what might be an example of the  required Java code.    How do you upload a file to an FTP server? .   Use it as a beginning but you will have to modify it to work with AI2..  To build YOUR extension, you will need a basic knowledge of how to program using Java., perhaps the suggestions here:  https://www.google.com/search?q=How+to+program+in+java&oq=How+to+program+in+java&aqs=chrome..69i57.8159j0j7&sourceid=chrome&ie=UTF-8  

Some examples of 'built' extensions:  MIT App Inventor Extensions  

Here again is the link Taifun provided above showing the MIT html describing how to build your own extension:  http://ai2.appinventor.mit.edu/reference/other/extensions.html  

To write the Java source code you will need a Java compiler like  example Eclipse or Android Studio 2 or IntelliJ IDEA  .  These are free compilers.

Need more help?  Possibly  


Creating an extension is not trivial for someone who does not have any experience programming in Java.   Here is the MIT 'tutorial' showing how to build an extension:    App Inventor Extensions  If it were EASY to build a useful aix, there would be 100's of aix extensions commercially and/or free.  The MIT tutorial is a good beginning but it is not highly detailed. 

Can you build your extension?    Of course, but you may have to teach yourself some non-AI2 skills first.

Why build an extension yourself?    When MIT makes the next AI2 upgrade, the extensions you have from other sources will probably not work with the latest versions of AI2.  If the author of the extension you are using does not upgrade the extension, you will probably not be able to use that aix extension in your projects going forward.

When you build your extension, consider creating a simple tutorial showing how you built the and posting it here in the forum in the area for Extensions.   Hmmm you could keep the code 'secret' but what you show might inspire other non-Java programmers to build different extensions which they might share with the community.

What others say or do with respect to extensions as reflected in the AI2 forum extension section  https://groups.google.com/forum/#!categories/mitappinventortest/app-inventor-extensions   

--


How many short sounds can be loaded into AI2?


I know one answer is you can upload asmany as long as the total app length is less than 10 MB.

But say I have 500 sounds and in total the length is 4 MB, can AI2 handle this?

-- 
Just out of curiosity, what kind of app needs 500 sounds?
App Inventor seems to fail when there's a big number of anything, even if the memory is still OK.
Are you sure you need 500 sound files? 

I think a better solution would be to use Taifun's player extension and make one file with all the sounds.
His extension allows you to set where you want to start. Then start a clock when the sound is played and stop the sound after the desired sound goes to silence gap and before the next sound starts.
You will have to make a list of start positions and durations, but at least you don't have to upload 500 files.

-- 

just try it and let us know, if it works

and btw. instead of uploading 500 assets one by one into App Inventor, first export the project (aia file), open it using 7zip, move the files into the assets folder and then upload the project into App Inventor again

--
Jeff's recommendations:

I believe I understand what is happening here. 

AppInventor is hosted on Google’s App Engine system. App Engine places 
strict limits of how long a single transaction can run (60 
seconds). As you build your project you add blocks and upload 
assets. Each of these operations runs in a small amount of time. 

However when you attempt to upload a .aia file with a lost of assets, 
the upload is one transaction. If there are a lot of images, it takes 
awhile for these to get uploaded (another Google restriction). If the 
sum of the upload times exceeds 60 seconds, the transaction is 
terminated and your project upload fails. 

We are looking at several alternatives to avoid this problem, but for 
now there isn’t much we can do about it. 

You are welcome to try uploading your project to 
code.appinventor.mit.edu. This is a re-implementation of MIT App 
Inventor which is not running in App Engine and doesn’t have the App 
Engine related restrictions. 

-Jeff 

P.S. code.appinventor.mit.edu is reasonably stable, but we will be 
updating it this week, including moving it to different hardware, so 
there may be some (hopefully short) downtime. 


--


How to create bus tracking apps in real-time?


Hi. i am ferr. i am student. i want to create bus tracking apps for my project. but I don't have any experience and knowledge about create app and programming. for this case, i want to create two app which is one for driver bus and one for client. driver bus need to send location to server and user can get the location display in map. how i want to do that? can help me :)

-- 

Navigation


i would use the location sensor for a specific way of "navigation". My wish is that i can pass a specific house and then the aplication ring. My Problem is that this isnt work as i wish...
How can i make this?
- Variables 
- Coordinates
- Compare the Coordinates
...
I ve just started to make this kind of aplication.
But there is another problem. I can pass the house near or far and doesnt pass the coordinates i ve written...
Thanks for help!



-- 
I think the problem here is that you are testing for an EXACT match on longitude and latitude.
That is very unlikely to happen unless you are standing at the exact spot where the measurement was originally taken.
A better approach might be to use a range of acceptable values.

So rather than doing
   get longitude =  -93.1256 and ...

Try something like

  get longitude >= -93.1255 and longitude <= -93.1257 ...

And adjust those values  so that a match is detected within an acceptable range.

Do the same for latitude.

-- 
is the rest so fine (picture)

-- 
I did it just like you said...
But it is still lacking :-(
Now he isnt looking for even GPS.
What he had done before. Whats wrong? How it works with the App Inventor navigations aplication?
Please help me :-)

-- 

Thats what i ve make...

-- 
To understand how the LocationSensor works  please read this article and do the two Projects 

Exploring with Location Sensor in AI2


The location sensor object is used to communicate with the global positioning satellite receiver (GPS) in your phone/tablet. When the LocationSensor communicates with the built-in GPS receiver, the GPS can determine the location of your device.  The sensor can also work with network/wifi location services.  Finding a location using the network uses very different techniques to determine a location. Location means, the device's present latitude and longitude or it can mean your street address.

Your simple app does not work for a variety of reasons:
1) You initially tried to find an exact latitude and longitude ...Scott explained why that does not work.
2)  A property of the LocationSensor called Accuracy (explained in the tutorial).  When you read the tutorial it explains that the GPS frequently does not know exactly where the Android is with any precision.
3) Your present code is an attempt to create a ring-fence; determining whether the device is within that fence is problematical.  The app might not be working for a variety of reasons depending on how often you program the LS to get a satellite fix or you are located South or North of the equator or to the West or East of the Prime Meridian (that affects how you set up your logic blocks) ..and you obscured the most important part of your geocoordinates. Also, the TTS code might be creating an issue with timing...AI2 is event driven,
4) Other things can go wrong:   Does your device have a GPS receiver?   If it does not and you depend on network, Accuracy is terrible .   Do you use the most accurate geolocation method   Provider = gps   and then lock it or do you use no settings and let the LS select what method it wants to use?  Do you see the GPS icon flashing occassionally at the top of your device screen..that shows the GPS receiver is trying to obtain a satellite fix.
5) the GPS receiver itself in many devices is not very precise, unless you monitor Accuracy continually, you will never know whether the GPS has a poor or very good satellite fix.

When finished with the LS tutorial perhaps read and do this tutorial 

AI2 Static Maps 104…calculate distances between points and add an Accuracy Square  

The Maps 104 tutorial describes Accuracy in a different way than the LS tutorial.

There are several solutions to your original problem, knowing when you arrive at a particular location.
Solutions include:
1) Making a ring-fence.   The following shows how to use a ring-fence properly http://www.appinventor.org/bookChapters/chapter18.pdf  in the section called Programming Complex Conditions
2) Using the LS DistanceInterval property to determine how close your device is to a certain point  (google the forum for a discussion that mentioned   Halte Alarm ..Christophe solved his problem that way.  DistanceInterval is discussed in the LS tutorial
3) Calculate the distance from the Android's current location to the desired location every minute or so, when the distance is small, you are there  (the second tutorial demonstrates several ways to calculate distance).  You will have to write code to poll the calculation.
4) You can use a Google Static map to display both the location you are interested in and the Android location  so you can see on a map ..look at the tutorials here https://appinventorforfun.wordpress.com/tag/mapping/ 
5) When all else fails look at a paper map, phone the residents of the house and ask them if they see your Android outside perhaps?

Hope this helps Nico.  When a developer realizes the GPS in phones is basically stupid, he/she can program around the device's limitations when he understands how the hardware and software tools work.

-- 
I have used the first option with the ring fence. It works but not perfect...
In the first picture i show wich coordinates i used. If this were the house i search and cross the street by the house the phone must be ring.
The black points are my coordinates...
Then i look wich coordinate is higher an place them into the field (second picture)



Must the fence be smaller?

-- 
It MAY work, but the problem is that you have a loop in your code. The code will make tts talk over and over again as long as you are in that are.

I have an app that will be releasing in the market next week with MANY gps features.

-- 
Without seeing the interval of your ring fence, I cannot comment as to whether the ring-fence should be smaller or not. See below-you will have to experiment with how small the box you monitor is to get the best results. From the points on the map, it appears the box is fairly small, possibly it actually needs to be larger ...experiment.

The area you are in has tall buildings.  Using your GPS there is like using the GPS in a canyon.  Buildings are probably preventing your GPS from getting a satellite fix with a lot of satellites.  When very few satellites are used in a 'fix', the Accuracy value increases dramatically.  It is easily possible your GPS reports a location that is as much as 50 meters away from where the GPS says it is.   Are you monitoring the Accuracy?  You read about it in the links provided.  If you monitor accuracy, you can eliminate geocoordinate readings that are more than say 5 or 10 meters distant from the true location. 

You read the LocationSensor tutorial, you recall that the metric way of looking at   0.00001 of a degree of latitude is that 0.00001 deg converts  to 0.9144 meters. The measurement tells us, satellite positional information can be reported is to a precision of 0.9 meters.  The satellites report positional data using five decimal place precision.  Does this mean that when a GPS gets a fix on multiple satellites that the smallest distance resolved should be 0.9144 meters?  No.  For other reasons, the best accuracy possible with specialized GPS receivers is on the order of  three  meters.  

Depending on how frequently you update the LocationSensor, Hossein's comment might be correct.   The TTS can interfere with the LocationChanged depending on timings. I would put the TTS in a separate block that controls how often the LocationSensor is updated.

Is it possible to do what you want, getting the phone to vibrate or the TTS to speak.  The high buildings means the Accuracy is going to probably be a large value.

-- 

updating php page



I have been working on updating php page lately, I have attached my blocks please have a look at it. It works until I try changing the age. I want to change the age as i change in the app to my php page too.

-- 

My PHP code is 


<?php
$age = $_GET ['age'];
echo "Rachita_age_is--".$age;
?>


Also when I was trying to put the blocks together, I found this error, "Segment: Start is less than 1 (0)" what does this indicates?

web_update.PNG 표시 중

-- 
try this
and yes, the value will be available on your page only temporarily

-- 
this is my example about PHP, GET and POST, maybe can help you.


-- 
For the indicated block, it doesn't works and now I don't get the values in my label., I have tried it even using the put webURIencode block to update haven't been successful.
-- 
For the suggested forum news, to my surprise I have gone through your example link before, also tried it. but my this code issue I'm not able to solve. 
Do go through it once and let me know where I have gone wrong.

-- 
an anyone help me please !!!

-- 

language


i want nepali language in text to speech

-- 
Look here: http://ai2.appinventor.mit.edu/reference/components/media.html#TextToSpeech
You can find the supported languages for your device and set the language and country code to the code you need.
Nepalese is certainly supported.


-- 
i can't get nepali language in language option. where can i get plz mail be back. i need nepali language urgently.

-- 
I know less that you do. Drag a TextToSpeech. AvailableLanguages into your workspace. Connect to the AI Companion with your phone, click on the block with your right mouse button and choose DoIt. You will see a list of supported language codes for your phone. My phone does not support Nepalese, but maybe yours does. Set this code in the designer as language code or with set TextToSpeec.Language to ...
Otherwise Google for a Nepalese text to speech package.

-- 


Google search using ActivityStarter to only work if a specific label is empty


I have created an app that uses a barcode scanner to get the ISBN number of a book. After the book is scanned, the ISBN number displays in a "results" label. The user can then select the "Search" button to call an ActivityStarter which pulls up a web browser and searches for that ISBN number.

My problem is that I do not want the Search function to work if the "results" label is empty (that is, if no ISBN number has been captured). I've tried to accomplish this with several different varieties of if/then blocks, but have not had any luck. These are what my blocks look like currently:

I've tried a couple of different things and either 1) the "Search" button is just permanently disabled, even if there is an ISBN number in the results label, or 2) the "Search" button is enabled and continues to pull up a blank search page in the web browser, even though there is nothing in the results label.
Any suggestions?
-- 
like this, you never will be able to touch the button again, because you set it to enable = false
what about just displaying a notifier "Please first select an ISBN number"

--