If else statement is not working


image

The images above are my app in designer and blocks interface.
My global final value is equal to 15 as shown in the third column text, but why the if-else statement does not work and display the LED status to "Unknown LED", which should display "LED1"? I am beginner to MIT APP Inventor. Please help me, thanks.

There is no Problem with the If/else Statements, the problem is that app inventor runs only in one thread(one line at a time) which means your If/Else statements is run before the Web1.GotText Event. This causes the variable to stay at its initial state.

1 Like

Put the If/Else statement after the "set global final to" block.

1 Like


I tried both solutions, still get the same result.
I use "get responsetype" to know the data type of the get response content and it shows me in text type. Thus, I change the normal equal to compare text. But it still get the same result.

Try using the "Mathematical =" block

I think you have too many If-else's, but that does not result in the error.

Mayank_Kumar is correct about the need to move the if's to the Web1.GotText Block, but they should be comparing integers and initially your code should ensure the responseContent is an integer.

Data_Via_Web1.aia (3.7 KB)

I think I should try explain answers better just like you and others do, I am a bit too bad at explaining things.

It would be instructive to point your desktop browser to that local IP address, then use the browser's Display Source (Ctrl-U?) option to see the text of the web page. This should expose any whitespace characters that might interfere with the lookups in AI2.

Copy the text and paste it here, for further discussion.