Using Blocks in Another Way

Hi everyone!

I wanted to show some tips which I’m using in my projects. I hope you will like it!

Reduce Blocks - Using Boolean Values


Bad           image

Better        image

Best       

Blocks Saved - 6


Enabled, Checked etc. properties are returns and needs boolean, so you can use them in **condition statements** directly. You don't need to use "=" block.

This is not only for checkboxes and buttons. You can use that in almost every component.



Reduce Blocks - “Any Component” Block


If you need to change component’s properties at runtime, you may prefer to use “any component” block.
image

Let’s imagine you have 4 buttons in your app, and you want to change these button’s properties such as image, text, width . . .

And probably you will do that:

Don’t

With “any component” block’s magic:

Do
image

Blocks Saved (for 4 components) - 6


  • Easier to add new component to list
  • Less blocks
  • Change once, apply for all :sunglasses:


Returning the Last Item in Any/Dynamic List


Yes, this is possible with “length of list” block.



Making Formatted Countdown


If you need a countdown in your projects like “13:07 left” etc. you can use that:

To find out how much time is left, it has to be shown somewhere except the label. So I used Linear Progress.

You need to write how many seconds to finish countdown in LinearProgress’s Maximum Value and Current Progress properties.


For Clock component:

And you need to put these blocks under LinearProgress.ProgressChanged



That is all!

This is my first Guide topic, so it can be any mistakes. Sorry for now. :sweat: I will try to add more guides soon. :smiley:

73 Likes

The idea with bad, better, best is good.
Feel free to make more topics like that.
:+1::+1::+1:

18 Likes

Nice tips, I wanted also to make something like this, but you were first. Again, nice tips and everyone, use them

4 Likes

@yusufcihan thank you very much for the tips! :hugs:

2 Likes

Also, @yusufcihan can you add the returning procedures and the way we can use them to the list? They’re also very useful, but the average user doesn’t know about them.

2 Likes

Thank you :iphone:

1 Like

Nice tips :+1::+1::+1:.

1 Like

The Problem with this is that It Sometimes freeze the Application other than that Awesome !

2 Likes

No, it won’t cause any freeze because this method uses built-in blocks. Also, you can find this block since MIT App Inventor.

2 Likes

But when i set kind of a Large List of Images It Freezes until everything Loads.

I used this guide for an upcoming app of mine, and it’s amazing now thanks to you.

1 Like

Great topic. I had already thought on some of those things but others will help me a lot.

But when i set kind of a Large List of Images It Freezes until everything Loads.
I don’t know what is your project, but if you are dealing with many components may be you could create 2 blocks for this, and split the events between them.

Example: If the problem is with large images, you can use a block only to load images, so the others components won’t freeze. Then you can call a procedure to load images or something like this.

Or if you know when the images will be loaded you can resize then before it, creating smaller images to be shown. at the buttons for example.

I have an app where the users can send pictures taken with the camera. Sometimes one picture alone is 3MB, it would make my app super hiper slow since I show about 10 - 15 pictures at once. So when the user take a picture the app generates 2 pictures picture12345.jpg and picture 12345-hd.jpg and send them to the server.

The app load picture12345.jpg first and if the user click the picture it will download 12345-hd.jpg from the server in a gallery.

2 Likes

This has given me a different views on blocks. Never again will I repeat useless blocks.
Thank you!

3 Likes

Thank you, your tips is awesome… :+1:

1 Like

Great Idea bro. Thank you

2 Likes

For the " If , Then , Else" statements would it be the same for java code?
So this is what I have so far. I’ve taken some basic java course so i know a little
~ CODE ~

String DarkColor, LightColor;
DarkColor = “Black”;
LightColor = “White”;

@SimpleFunction(description = “Block for Light Theme”)
public String SetLightTheme(String LightTheme) {
LightColor=LightTheme;
String res = LightColor;
GotValue(res);
}

@SimpleEvent(description="")
public void GotValue(int result){
EventDispatcher.dispatchEvent(this, “LightTheme”, result);
}

If (LightColor != “White”) {

}

So if you look at the last piece of code, this is what I started for the conditional statement. I feel like im on the right track but not sure if im heading in the wrong direction. Any advice or tips would be greatly appreciated. If you see something wrong point it out.

DO NOT GIVE ME CODE!! I WANT TO FIGURE IT BY MYSELF. Just give suggestions.

Yeah, but don’t forget that these statements starts with lowercase.
if
else
else if

And your if statement is not in the function, it is outside of event.


By the way, it is wrong topic to talk about extension development. :slightly_smiling_face: I suggest you to open new topic about your next questions.

3 Likes

I want to send you my blocks so you can optimize it.

I really need to learn to use more Any Component. Keep providing more guides how are you. :smiley:

what about learning it yourself?
you can use these tutorials as examples…

How to work with the advanced features

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

Taifun

2 Likes

I have tried to replace some blocks with Any Component. But this has been my attempt.


I try to create three Navigation buttons. Even so I feel it has many components. Any advice?

Update: I simplified it a bit.
blocks (5)
blocks (6)
blocks (7)

1 Like