How to build a random button picker with the blocks?

66 views
Skip to first unread message

banshe123

unread,
Jul 7, 2016, 5:24:26 AM7/7/16
to mitappinv...@googlegroups.com

Hello lovely people ;)


I am a beginner and I don’t have any experience with coding etc. and I need help ;) The first screenshot attached here shows my screen, and as you can depict from it there are two buttons- the first one is called RIGHT BUTTON, and the other one is called WRONG BUTTON. This is because clicking on the RIGHT BUTTON will open a next screen, whereas clicking on the WRONG BUTTON will result in going back to the previous screen. I thought that this is kind of boring :D that’s why I want to build something with the blocks that would choose randomly one of those buttons to be right and the other one to be wrong after the screen has initialized. To make it more clear. Every time I start the app I don’t know which button out of those two will take me one screen further- it could be the first or the second button- I want this to be a random pick.


Now, I have tried to build something like this, but I can’t find a suitable block, as you can see in screen shot 2 :D I assume, that this isn’t the way it should look like, but my skill is too low at the moment. I also assume that I will need an "if,then" block" I would be really grateful if someone built it and made a screenshot and post it here ;)


Basically, I am kindly asking for help. I have been looking on the internet for a tutorial etc. but I couldn’t find something that would really help me.


Thank you very much in advance ;)

screenshot 1 right and wrong button.jpg
blocks screenshot what to fit in.jpg

Abraham Getzler

unread,
Jul 7, 2016, 11:47:42 AM7/7/16
to MIT App Inventor Forum
Don't use multiple screens for this.

Reuse the two buttons by replacing their .Text attributes with "Right Button" or "Wrong Button", depending on a random choice.
Once you decide on the first button's .Text, that determines what to put into the other button.

To process a button click, check it's .Text value against "Right Button" and respond accordingly.

There is a severe screen limit in AI2, so learn to reuse screens.

You don't need to buy a new lawn mower for every new blade of grass.

ABG

banshe123

unread,
Jul 7, 2016, 12:44:43 PM7/7/16
to mitappinv...@googlegroups.com

Dear Sir,


at first I would like to thank you very much for your response and advice. The problem is that I cannot really take advantage of it- I mean- I don’t understand everything, I have actually no experience with creating lists, and therefore it’s difficult for me to interpret what you mean by:


“To process a button click, check it's .Text value against "Right Button" and respond accordingly.”


What shall I respond to? ;)


I definitely don’t want to bother you in any way or take away your time, but personally, for me the most helpful would be a screenshot of the blocks built correctly. It would be very nice of you, if you did it, I would be very grateful, because solving this issue would take the development of my app to the next level, this would be a huge progress, but of course my intention isn’t to force you to do it etc. I just would be very happy if, because of your help, I could keep working on my app :) 

Abraham Getzler

unread,
Jul 7, 2016, 1:17:57 PM7/7/16
to MIT App Inventor Forum
Sorry to spoil your fun.

Read the Books and Tutorials section of this FAQ to figure it out.

P.S.

A man walks into a hardware store, asks for a chain saw.
The dealer fills it with gas and oil, hands it to the customer.
The customer returns later, all hot, sweaty, and dirty, and complains that it doesn't work.
The dealer takes the chain saw, looks at it, and pulls the starter cord.
The chain saw roars to life.
The customer jumps back in surprise, and yells
"What's that noise?"

Moral:
Read The Fine Manual

ABG



blocks.png
Designer.png
Two_Buttons.aia
2016-07-07 13_10_28-5554__build_.png

banshe123

unread,
Jul 7, 2016, 1:51:02 PM7/7/16
to MIT App Inventor Forum

Dear Sir,


I can’t tell how grateful I am. I want you know that you it means a lot to me that you sacrificed your time to help me, it’s almost impossible to put it in words how much I appreciate it.  You’re a very good person, because you help people disinterestedly and furthermore- you don’t even know them. Nowadays such behaviour extremely rare, and Sir you a have a good heart. I admire your attitude and I wish you all the best- you undoubtedly deserve it :)  

banshe123

unread,
Jul 8, 2016, 6:54:58 AM7/8/16
to MIT App Inventor Forum

Dear Sir,


I have been trying to fit your example my needs for the app. The basic problem is that I cannot make this app on a single screen, or at least I am not able to do it. The idea is that the number of buttons shall increase with every level and only one shall be correct and the rest wrong. The thing is, I want that after clicking on one of the previously randomly selected buttons the app will take me to the next level, and clicking on the other one will take me 1 level back. I am again in trouble with the blocks, I don’t understand why it doesn’t work, everything seems to be fine for me from a logical point of view, and I don’t know where I made a mistake. Sir, if you only have, please help me. I have spent literality hours sitting in front of my computer screen and still haven’t come up with an idea to solve the problem. There is also something wrong with the companion connection, after some time the app crashes.

Two_Buttons.aia

Abraham Getzler

unread,
Jul 8, 2016, 9:12:12 AM7/8/16
to MIT App Inventor Forum
It was faster for me to make a new example, than to download and open your .aia file.
In the future, please post screen shots of your blocks, to make reading faster.

When I see a request for a variable number of buttons, that tells me you need a List View and a list.

See the attached blocks, Designer, and run time screen shot for how to do this.

Again, do the tutorials.

ABG



blocks.png
Designer.png
2016-07-08 09_04_42-5554__build_.png

Ghica

unread,
Jul 8, 2016, 9:17:31 AM7/8/16
to MIT App Inventor Forum
How many levels will your game have? App Inventor allows a maximum of 10 screens.
Besides, the companion crashes because you do not open screens in the right way.
See this: http://ai2.appinventor.mit.edu/reference/other/manyscreens.html  and: http://puravidaapps.com/manager.php

What you should do, is starting with as many buttons on Screen1 as you expect to have levels. Make them invisible except the first 2. Put all in a list for easier manipulation.
When going up a level, you make a new button visible, when going down a level you make the last button invisible.
Have also a list of visible buttons, and when starting a level, you pick a random element from it that you make the right button.
And learn more app inventor.
Cheers, Ghica.
Reply all
Reply to author
Forward
0 new messages