Producing a Random Number

blocks (1)
blocks

What i’m trying to do is to create a random number generator where if a number = 1 play Jack Benny.

Nothing happens when i hit the tuner button.

Any ideas?

If the random number =2 play WB

1 Like

Audio_Sources it will always be 0 since it is not assigning a value, just comparing.

  • Audio_Sources can only have 2 possible values, if it is not 1 it will be 2, so what is the need to perform a new comparison?

A very good way to learn App Inventor or Kodular is to read the free Inventor’s Manual here in the AI2 free online eBook App Inventor 2 Book: Create Your Own Android Apps … 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: App Inventor 2 Book: Create Your Own Android Apps

How to do a lot of basic things with App Inventor are described here: How do you…? .

Also do the tutorials Our Tutorials! to learn the basics of App Inventor, then try something and follow the Top 5 Tips: How to learn App Inventor

Taifun

1 Like

I vreated that label. what i want to is take the number from the random gemerator and put it in a sub routine.

1 Like

remove the first if statement and set the global variable Audio_Sources like this

set global Audio_Sources to random integer from 1 to 2

Taifun

1 Like


Like this?

1 Like

:point_up_2:

1 Like

Thats What im asking u?

1 Like

Assuming Audio_sources = 1 the process would be as follows.

image
I think you should improve your logic and then put your blocks together.

If it is not worth 1 it is because it is worth 2, I don’t know why you put a conditional again.
It’s about common sense

1 Like


also usually you use only 1 player component
to play another audio, just set another source before playing
it helps to do some tutorials to learn the basics…

Taifun

1 Like

If i dont do it that way the audio players wont stop

1 Like

Unclear
Your project is about playing a random audio, isn’t it? What about describing your requirements?

Taifun

1 Like

A post was split to a new topic: I don’t know how to type

What do u mean?

Please describe your requirements
Taifun