2015년 1월 3일 토요일

Basic Random Function


I'm currently creating a quiz application and have the app setup to ask questions starting from 1 to X each time but I would like the questions to be random each time and at the end of the total answers to go to a navigation screen. I have unsuccessfully tried to do this previously as the random functioned seemed to work, but didn't know when to stop!

I've attached images of my blocks and would appreciate it if anyone could have a look and point me in the right direction? The screenshots are before I added the random function.



--
The screenshots are before I added the random function.
It would really help if you provided a screenshot of your relevant blocksafter adding the random function, so we can see what you are trying to do, and where the problem may be.

--
Apologies for the previous pictures, they were a little muddled.

The error I get (which from memory works sometimes if i change the greater than number? i've tried lots of different ways with little success) is the operation pick random item cannot accept the arguments: My first question in the list. 





--
the pick a random item block expects a list and not a list item...
also you like to get the corresponding question text to the random question, don't you?
which means, it does not make sense to use the pick a random item block inthis case...


let me recommend to use the random integer block instead, see also this example How to pick a random item from a list without picking duplicates?
removerandom.aia

--
Thank you.

--
One follow up question. Will I need to apply exactly the same blocks in the link to my screen initialize block and next button block? That's when I want the first question to appear and the next button to grab the next question.

--
yes...
as you can see, there is some redundancy...
you can create a procedure which gives you a random index and call that procedure in both events...

--
to display the answer, do not get a new index, use the existing index to display the correct answer
also you can create a "next" procedure to be called from the initialize and NextButton.click event to avoid redundancy

--
Thanks Taifun, from the link you provided (and a little trial and error), i've got it working perfectly.

I have a couple more follow up questions (sorry for being a pest):

How do I enable the notifier button to go back to a menu once all the questions have been asked (i've used both variations of the attached screen shot)?
Is it possible to apply a style to the notifier (external style sheet or markup)?
Given a menu with multiple options, how would I choose a different list/s as my index (i currently have 8 screens per quiz section) on selection of a menu item?
Finally (phew!), is it possible to apply basic styles to the list text (comma separated) using a style sheet or markup?



--
which options do you display in the notifier? if you display "Menu" as one option, then using the text block "Menu" should work
to use a notifier component would not make sense there...
New formatting possibilities with the Notifier

Given a menu with multiple options, how would I choose a different list/s as my index (i currently have 8 screens per quiz section) on selection of a menu item?

sorry, I don't understand this
 is it possible to apply basic styles to the list text (comma separated) using a style sheet or markup?


--
If you have 8 screens PER quiz section, that implies that you have MANY screens... The maximum you should use in AI is 10.  Please read my tips on screens...
For my App Inventor Tips, visit TwoDogApps.com by clicking here!

--
I've attached a screenshot of my notifier block. I was trying to launch the notifier on the end of the quiz (which works), but the button (I was using both blocks in the above post to test) just dismisses the notification.

To explain a bit better, my main screen is a menu with 8 buttons (each button represents a topic), on button press a new screen opens with the blocks from my random quiz. I have a single screen for each topic. Each of those screens currently has a question/answer list with different csv's. Rather than having eight screens, is there a way to dynamically choose a different list depending on which menu button is chosen?

Workaround link is very helpful, thank you.



--
Thanks Enis, some helpful tips!

--
You need a show choose message instead of a show message dialog, else the after chosen event will not fire
Rather than having eight screens, is there a way to dynamically choose a different list depending on which menu button is chosen?
depending on the chosen menu button load the question and answer list from the csv files, like this you could do everything in only one screen without redundancy

--
That's what i would like to do! Do you have any links to a tutorial or example on how to achieve this?

--

Flashing the camera LED thru activity starter?

Hi, Apparently AI2 misses a built-in function to access the LED of android devices. I was wondering if any of you had found a workaround for this, using the activity starter for instance. Thank you very much.


how can i create a character who talks?

i want to create a character like talking tom, who speaks but also i want to unfold some images about what he talks about but i cant find how to do



What have you tried Adrian?

It is probably impossible to duplicate Talking Tom using AI2 blocks but you could come close.

To talk:   use the TextToSpeech component     several of the tutorials here show how to do that MITs tutorials    http://appinventor.mit.edu/explore/ai2/tutorials.html 

To interact:  You might look at the AI2 free online eBook  http://www.appinventor.org/book2 ... the links are at the bottom of the Web page.for some ideas.

Graphics:  Animation of a character in AI2 is fairly primitive, AI2 is not a game engine, however you could use the Canvas and some image sprites to simulate interaction.   Here is a link where someone is doing something similar, but with text instead of TextToSpeech https://groups.google.com/forum/#!category-topic/mitappinventortest/zQEkdomm9P0

What do you want Tom to do?   Ask a specific question and you will get advice.


Dog Gone! ..a tutorial and matching tile game for AI2


Dog Gone! .. an AI2 Tile Matching game and tutorial is now here:  https://appinventorforfun.wordpress.com/2015/01/03/dog-gone-a-tile-matching-game-tutorial-for-app-inventor-2/  

The complete tutorial and links to the final app aia file  and an template file that contains all the game resources are at the link posted above.

If there are issues following the tutorial, please report them here (or on the app's Web page) and I will make changes/ answer questions as necessary.


--
Very slick!!!  Congrats Steve!

--
Thank you! I was just planning to make a memory game, so this is at the right moment.


--

Rounding

I have a question. How can I round a number but not like this: 5,665823 ---> 6 but I need one decimal place: 5,665823 ---> 5,7 ?? 
How can I do it ?? Or can I set a count for visible signs ?? (There will be visible only 5,6 not 5,665823)


Blocks Editor Bug

Hello 



How to fix it its appered random.I need click area and move block.



It's actually a browser issue... when it happens to me, although rarely, I refresh the browser tab and it all fixes itself.  I'd flush your browser's cache as well...


How to create a button to save the drawing in paintpot app ?


I have a question. I am creating an application of paint, similar to paintpot tutorial, I would like to create a button to save the picture drawn in the gallery, I'm more hard to do it. Can anyone help me? 

I'm using MIT App Inventor 2 in Windows 7 Ultimate platform, using Google Chrome.

--

Hello,
What you want to do is save the canvas.  The canvas is the control amd surface you are drawing on.  Here is a link to Save the Canvas  .  The blocks there show  how to use a button and save your creation.  You will use a TinyDB control.   Try this, it is not too difficult.

After you work with the example and include it in your example, please return here and let us know if this suggestion answered your question.

--

Thanks Steve !

Worked perfectly, thanks for the help. 

I'm new in App Inventor, and did not know the DB Tyne. 

Until next time! 

--

Thank you very much Clever for letting us know all is working fine.  :)

Have fun with AI2 and your projects.

--
Thank you so much for the link to save the canvas.
I had trouble finding the 'call TinyDB.get value' function (bottom purple).  I looked under TinyDB but couldn't find one that fit in the notch.
Any help would be appreciated!

--

The button2 image on the right might be what you are trying to do, it a variation on the Canvas save hint:

If you save a png or jpg image to the database with TinyDB, the object you connect it to must be compatible...in this case a Canvas or Image object, both of which accept image files.  

Did this answer your question?    Please let us know.    If this example did not answer your question, please post some blocks.   Thank you.

--
Yes, the purple function on the right is what I'm looking for.  (attached)
I checked under canvas list but still couldn't find the same function.
I've attached a screenshot of my only options in TinyDB.
I'm sure it's right under my nose - I feel so stupid.
I really appreciate your help!



--
@ Vasha  ---  Your problems is this; there is a component calledTinyDB.  There is another component called TinyWebDB.   You are looking for the TinyDB in the TinyWebDB control selections.  You have to first put a TinyDB  component on to your Design screen before you can find the TinyDB blocks on the Blocks screen.  Check to see if your project has a TinyDB screen.    Does it.  If so, you should now be able to find the component.

Were you successful?

--
Doh!  I didn't know about the TinyWebDB.  Works like a charm now.  Thank you so much!

--
With this example, will the image be saved to my phone as a file that I can send to others?

--
With this example, will the image be saved to my phone as a file that I can send to others?
yes

--
Where does it get saved? I cannot find it.

--
If you save an image using the TinyDB, the image gets saved in the AppInventor folder on my tables; specifically   AppInventor/storage/emulated/o/AppInventor/assets  on my Tablet, it might be a diffeent place on your phone.


The TinyDB itself only stores text.  The TinyDB stores the path to the images and the images themselves are stored in the AppINventor folder.   Actually, all the resources for any AI2 app on your 
device is stored there I believe.  That means there might be files from various app there, not only your PaintPot app.

Look for the image in the AppInventor folder that should be on your phone.  Did you find your stored images?

@ Taifun .... is this true.   If not please correct me.

--
if you use this example How to save a canvas
the image will be stored in the root directory of your SD card
feel free to add a directory, for example file: MyDirectory/MyCanvas.png

edited by Taifun: for the path do not use "file:///mnt/sdcard" here...

--
So if I use image picker, will it show up in my gallery? If not, how do I do that?

Taifun wrote:

if you use this example How to save a canvas
the image will be stored in the root directory of your SD card
feel free to add a directory, for example file:///mnt/sdcard/MyDirectory/MyCanvas.png

--
The file directory did not work, it just randomly created its own folder in my sd card. Any advice?

--
it works without the file:///mnt/sdcard...

--
Can't see the pic

--
@Muneeb: It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

--

speech recognition string comparison !


I want to compare the speech recognition string input to the preset text string and if it matches correctly, then I want to send a a character, say 'A' over the bluetoothclient. Any suggestions?

--  

first do the tutorials http://appinventor.mit.edu/explore/ai2/tutorials.html to learn the basics of App Inventor, then try something and follow the

-- 
thanks for the links. but, i have already gone through them earlier and did the bluetooth part, i Only need help in the string comparison from user input via speech recognition. The string is being detected by the app, only the comparison to that of previously set string. 

-- 
What have you tried.   You have not shown any blocks for users to comment on and provide advice.

Where is the recognition text being displayed?   In a label?   In a TextBox?     Where is the comparison text?

The way you compare is    using the IF..then blocks...

if label1.text = label2 text 
then    do something
else
do something else

This example will work in some situations:

Your comparison could be in a Notifier or in a label (I would use a label because both SpeechRecognizer and Notifier have some lag to them and not using a Notifier will help avoid collisions.

SpeechRecognizer is described for AI2 blocks here http://ai2.appinventor.mit.edu/reference/components/media.html#SpeechRecognizer     There are few options when using the Android feature with AI2. Eclipse and Android Studio developers can do many things with SR that App Inventor cannot.

The downcase block (same as the upcase block but use the carrot to change the block) is in the code because AI discriminates between      this is the text     and    This is the text;  the statements are not equivalent because AI2 and Android are case sensitive.    If you need to discriminate between the two, then you need to write more code.    See http://www.appinventor.org/bookChapters/chapter18.pdf and http://www.appinventor.org/bookChapters/chapter20.pdf   for possible ways of doing that.

How about trying some blocks.   Be aware, Android's SpeechRecognizer is fussy and it does not always return what you expect.

-- 
Thanks steve, the result from the sppech recognizer is being displayed in a label. And, what I'm trying to do is this :
If user input i.e. speechrecognizer.text = "hello"...send character 'A' over bluetooth (as A is command for led on in my arduino code) & if speechrecognizer.text = "bye"....send character 'B' over bluetooth (as B is command for led off in my arduino code). 
I'm not really worried about the upper and down cases. All i require is the string input from user and then the app to send a particular character in response of correct match.

-- 
It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

-- 

hello, I am done with the speech recognition comparison of input part. Thanks to the blocks you provided. 
The new issue is this : The Commands that I send for a particular speech input, can that command be send for a range of the accelerometer sensor reading?

I have done this but the output is always labeltext2 only. What to fix...?

 Untitled1.png

-- 
I am through with the SR part. And yeah, you are right, Android's SR is very fussy...so can you suggest any other SR input from the user that works better than this?
And also do check the file I have uploaded, facing a problem with the Setting up of range for the accelerometer ( x axis) reading and if reading is positive, do this...else do that but the problem is it is always 'doing that'....check it out.

-- 
Google Android has two SR engines, one actually runs on the device, the other runs in the Cloud (you have to be connected to the Internet).  There are other third party SR engines :  https://www.google.com/search?q=android+speech+recognition&oq=android+speech+recognition&aqs=chrome..69i57.7183j0j7&sourceid=chrome&es_sm=93&ie=UTF-8    .  If you load a third-party SR and change the SR engine in the Android Settings (I think one can do this but do not know), you might be able to control the third party engine with AI2.  Realize, AI2 can only adjust a few things in the SR; if you want the full capabilities of Google;s SR, you will have to use Eclipse or Android Studio and use Java to program.

You should be able to do what you want to do regarding the acceleraometer... I have no time at the moment to debug... sri .... the issue might be a timing issue.  You may have to use a Clock component and do some creative things...  I can tell you now, the block   random integer from 1.56.... is wrong.    the values have to be integers.   You can modify that out side the block by converting values.

-- 
I suppose the cloud SR is for online google search..:/....hmm...i added another TTS and SR engine to my device but google services are way better.

And, yeah I did used the integer at first but that did not solve the issue. A particular integer or number is doing the job but given the accelerometer sensor is very sensitive, so getting a partticular reading and staying at it would be difficult...or impossible. Its better to set up a range for the reading...which is not working.

-- 
The Cloud SR is not just for online searching; it can be used in your app.

I suspect you should be evaluating Xaccel  using   a structure like If Xaccel > a value  and Xacell< a second value  THEN do something   else   do something else.

Try some blocks.   Also the Shaking block is probably continually cycling the Vibrate ... a problem might be that it triggers a new vibration cycle before the existing vibration period ends giving your app a sort of 'heat attack' perhaps?

Also, SR might be interfering with the accelarator messages.  Consider, AI2 does NOT process multiple threads.   Each command and process must finish before the next starts (really a little more complicated than that but a good simplification ... one thing has to finish before the next thing executes.)

Try some blocks.   Only you know how you want this to perform.

-- 
i got the comparing of accelerometer readings in the range and the labels display correct text and they do keep updating as per the readings. however the call TTS part isn;t working and due to this other speech recognizer block and shaking block too get disturbed so I disconnected all other blocks still the Call TTS part isn't working properly. what might be the error...?

 Untitled2.png

-- 

How to parse duplicated tag?

I have a big problem to parse Yahoo Weather XML.
I want to parse forecast block, but in this piece, XML have a duplicated tag, as shown below.
How to work around this problem?

<description>
<![CDATA[
<img src="http://l.yimg.com/a/i/us/we/52/33.gif"/><br /> <b>Current Conditions:</b><br /> Fair, 5 C<BR /> <BR /><b>Forecast:</b><BR /> Fri - Partly Cloudy. High: 8 Low: 3<br /> Sat - Mostly Sunny. High: 10 Low: 6<br /> Sun - Mostly Sunny. High: 9 Low: 3<br /> Mon - Sunny. High: 8 Low: 0<br /> Tue -
]]>
<![CDATA[
Sunny. High: 8 Low: 1<br /> <br /> <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Rimini__IT/*http://weather.yahoo.com/forecast/ITXX0148_c.html">Full Forecast at Yahoo! Weather</a><BR/><BR/> (provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
]]>
</description>

<yweather:forecast day="Fri" date="2 Jan 2015" low="3" high="8" text="Partly Cloudy" code="29"/>

<yweather:forecast day="Sat" date="3 Jan 2015" low="6" high="10" text="Mostly Sunny" code="34"/>

<yweather:forecast day="Sun" date="4 Jan 2015" low="3" high="9" text="Mostly Sunny" code="34"/>

<yweather:forecast day="Mon" date="5 Jan 2015" low="0" high="8" text="Sunny" code="32"/>

<yweather:forecast day="Tue" date="6 Jan 2015" low="1" high="8" text="Sunny" code="32"/>

<guid isPermaLink="false">ITXX0148_2015_01_06_7_00_CET</guid>



I don't see duplicate tags in what you posted... I see a quick forecast in the first data set, and a full forecast in the second data set...



Quick forecast is not good for my use.
See full forecast, the tag is...?
i think "yweather:forecast" for every day of the week, if you parse including the day, is not good, because we have only five days.



That's called a 5 day forecast. 



Yes is 5 days... and the problem is duplicated Tag, Not 5 days. How to distinguish one day?



your XML is not the complete result of the API, is it?
I would convert the XML result into a list of lists using theXMLTextDecode block and then use list blocks like select list itemand lookup in pairs to get what you need
you also can loop through similar data using the for each in list loop



any XMLTextDecode(text XmlText)
Decodes the given XML string to produce a list structure. See the App Inventor documentation on "Other topics, notes, and details" for information.




Also see

for the duplication problem.



Yes is only the part with the problem, is a XML response of Yahoo Weather webservice (http://weather.yahooapis.com/forecastrss?w=721682&u=c).
Now try with XMLtextdecode and lookup in pairs, it's ok with WOEID extract procedure, but take error with forecast --> org.json.XMLTokener.end
Try with JSON format and it's ok, but... take error with this part, the error is "not well formatted pairs". I'm very frustrating....

forecast
0
1
2
3
4



I don't know if you've seen this yet.
Here's an entirely different approach, that throws away
all hopes of parsing the entire tree ...


That was designed to just search for one target  based on its delimiters.

Extend that procedure into a new procedure, called Multi_Parse,
which would return a list of all such targets in its input and those delimiters.

I'm guessing your target is a single day forecast?

Parsing a single day forecast should be a separate post, if you need it.


Using a real SOAP webb service with wsdl


Is there a possibility in app inventor to call functions og a soap web service which are defined in a wsdl. I only saw in tthe example url calls?

--
Yes, with Eclipse or Android Studio but not within App Inventor.  AI is an entry level Android compiler; you need a professional compiler with all their bells, whistles, tool kits and libraries.

WSDL is in XML format, so the only way to communicate would be using the AI2 Web component   which can read but not write.



any XMLTextDecode(text XmlText)
Decodes the given XML string to produce a list structure. See the App Inventor documentation on "Other topics, notes, and details" for information.

The explanation here Working with XML and Web Services  shows that you can read but perhaps not write.


--
you also can send XML format using the web component, but you will have to put it together manually

--

Stopwatch!!

please I want your help. I have  an application, the application is a timer. Stopwatch This works, but the last seconds was blocked by a normal timer. I think this is wrong?but I do not know what's wrong  I would help you watch please.The gave all large values ​​(10,100,1000) pieces of the application are Habits:




see here how to get a readable screenshot https://groups.google.com/d/msg/mitappinventortest/jhv5qdoKEhU/RlxpiBntozkJ



This is not my point !!!



my point is why not my timer " I have  an application, the application is a timer. Stopwatch This works, but the last seconds was blocked by a normal timer. I think this is wrong?but I do not know what's wrong  I would help you watch please.The gave all large values ​​(10,100,1000) pieces of the application are Habits" can i help me!!!



The problem sir is that no one can read the text on shown on the photo of your PC screen.   Please make a screen capture of your blocks so the people here can read your blocks and make suggestions about yourpoint.  Thanks.  Without the screen capture (either a png of jpg image); no one can help.