Random Procedures in App Inventor 2

73 views
Skip to first unread message

Sebastian Pichler

unread,
Sep 14, 2017, 4:56:50 PM9/14/17
to MIT App Inventor Forum

Hey guys!
I just can't figure out how to create a code where I have multiple procedures and i want a random one to start working.

My biggest issue is that I can't create a list filled with "call procedure"- commands.

Thanks in advance!

Abraham Getzler

unread,
Sep 14, 2017, 5:05:20 PM9/14/17
to MIT App Inventor Forum
You could create Clock components to execute each different procedure,
all of them disabled non-repeating, and make a list of them at
run time.

Then pick a random list item from that list, and use an Any Clock block
to enable that Clock.

At the end of each Clock.Timer event, disable that Clock
to ready it for the next time.

The Any Blocks are in a separate branch of the Blocks Editor
palette.

ABG

Sebastian Pichler

unread,
Sep 14, 2017, 5:11:07 PM9/14/17
to MIT App Inventor Forum
But that would be about 500 clocks....do you know if the AI can handle that?

SteveJG

unread,
Sep 14, 2017, 5:11:22 PM9/14/17
to MIT App Inventor Forum
There are certainly other ways but you can try using nested conditional statements  ...chapter 18 in the Inventor's Manual. for a very 
simple method provide you do not have hundreds of Procedures.



We want you to have fun with App Inventor so here are some resources to help you learn to use the AI2 tools  A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook   http://www.appinventor.org/book2 ... the links are at the bottom of the Web page.  The book 'teaches' users how to program with AI2 blocks.

There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro  and the aia files for the projects in the book are here:  http://www.appinventor.org/bookFiles  

How to do a lot of basic things with App Inventor are described here:  http://www.appinventor.org/content/howDoYou/eventHandling  .

Regards,
Steve

Taifun

unread,
Sep 14, 2017, 5:15:22 PM9/14/17
to MIT App Inventor Forum
I have multiple procedures and i want a random one to start working
what is the difference in these procedures? can you provide some examples of 2 or 3 example procedures?
Taifun

Sebastian Pichler

unread,
Sep 14, 2017, 5:17:05 PM9/14/17
to MIT App Inventor Forum
I do have hundreds of procedures...but if there is no better solution I might have to deal with this one, thanks:)

Abraham Getzler

unread,
Sep 14, 2017, 5:19:52 PM9/14/17
to MIT App Inventor Forum
You are confusing procedures with data.

Learn to work with files and lists, along with procedure parameters.
otherwise you will soon paint yourself into a corner.

Here is an example of a table-driven app ...

ABG

Sebastian Pichler

unread,
Sep 14, 2017, 5:23:58 PM9/14/17
to MIT App Inventor Forum
I The procedures only include messages.
For example:
One precedure:
Hello.
(wait 3 sec)
How are you?

Another procedure:
Hey:)
(wait 2 sec)
How are you doing?

Just to give you an idea:) So i have multiple messages that need to be together and with a delay. 

Taifun

unread,
Sep 14, 2017, 5:33:33 PM9/14/17
to MIT App Inventor Forum
One precedure:
Hello.
(wait 3 sec)
How are you?
Another procedure:
Hey:)
(wait 2 sec)
How are you doing?

which could easily made in only one procedure like this:
pick a random list item from a greetings list and display it
wait a random number of seconds
pick a random list item from a questions list and display it



Taifun

Sebastian Pichler

unread,
Sep 14, 2017, 5:38:53 PM9/14/17
to MIT App Inventor Forum
Yes, but this was just an example. What if one special greeting needs a special Question?


Abraham Getzler

unread,
Sep 14, 2017, 5:59:10 PM9/14/17
to MIT App Inventor Forum
Yes, but this was just an example. What if one special greeting needs a special Question?

It's still just data, only it needs a bit more structure  to it.
Here's another example, structuring a 20 Questions type
of dialog ...

ABG

Abraham Getzler

unread,
Sep 14, 2017, 6:12:08 PM9/14/17
to MIT App Inventor Forum
Regarding your waiting requirements, 
you can encode your delay amounts along with the test fragments, in a two column
tabular file, delimited by commas, with the text in column 1,
and the post-delay amount (seconds) in column 2.

Or you could change the Clock Timer delay between announcements
based on the text length of the pronouncements.

See the attached sample for Clock driven output.

ABG

blocks.png
Samaritan.aia
2016-07-20 12_31_29-5554__build_.png

Sebastian Pichler

unread,
Sep 14, 2017, 6:13:26 PM9/14/17
to MIT App Inventor Forum
Okay, thank you so much for your effort!
I guess I need to improve my knowledge about AI a little bit more but now I think I can do this:)

Abraham Getzler

unread,
Sep 14, 2017, 6:17:17 PM9/14/17
to MIT App Inventor Forum
For a multi-column table example with speech,
see this sample ...

ABG

Reply all
Reply to author
Forward
0 new messages