List numbering question


I have this listed canvas selector.
The global channel is filled with zeros on init, and the Panels is filled with the canvases.
The first version is only change the color of the first of selected canvas.
The first is chane the "0"s to "1"s for the picked ones, in the channel list, and the button_click should check if the actual channel value is not "0" then take the itmem number and change the color for each canvas by that item number, but it is only change the first.

The second one is when i modify the blocks, change the circled ones with according to the picture.
This ones is change the "0"s to the picked canvas's number in the list. The button_click check if if the actual channel value is not "0" , then take the value from the list and change the color of the canvas number equal with that value.
This is work fine.

So what is the problem with the first one? It should work too, in my opinion.

Hello Zol

I don't understand your question, it would help if your material matched your description - The '0's and '1's -why do you need a list of each?

Also, are you really using lots of canvasses - what is wrong with using sprites on a canvass?

Hi!
Sorry, I'm not too good at anglish when it comes to complicated text compozition.I try to make it more understandable.
Here is what is in the channel and the Panels lists.I call this on app start.


As you see, the 20 canvas is in the Panels list, and there are 20 numbers (all zero in startup) represented them in the channel list. The zero ("0") represent none of the canvas was picked yet, i.e. they are grey on the emulator.

  • In the first version, If i click on one canvas it is become green, and the represented "0" in the channel list become "1". And if it is already selected then deselect it. Become green, and the "1" in channel list become "0".
    And the list is printed on a label just for testing.
  • In the second version, If i click on one canvas it is become green, and the represented "0" in the channel list become their number in the list. If the first canvas then become "1" if hte fourth canvas then become "4".
    This is done by the following block.

Now if i click on the change color button on the emulator, that is the following block.


It is check the channel members one by one if "0" or not. If not then take it's NUMBER in the list and using that change the color of the assigned canvas.
THIS doesn't work somehow.
But if i change the procedure according this picture:

e.i. As i mentioned it is change the "0" to its numbers instead of "1" in the channel list.
And the Button is check if it is "0" or not, but this version it takes the VALUE of that list member, not its
number like before.
This is works fine as you see on the emulator picture this is recolor all selected canvas.

And for your question about sprites, i use canvases for one reason. Sprites doesn't have color feature, and it will be colored by a color picker, not just green and red. It is like a color pixel editor.

  1. The first block, When any Canvas Touched, is used to indicate which canvases have been selected.

  2. The second block, Button 12 click event, changes the colour of all canvases selected, ignoring those that have not been selected.

You have a method that works and one that doesn't - so I have to ask, why not just use the method that works?

As far as I can tell, you have 20 canvasses on one panel. Your code suggests there is more than one panel - how many panels are there? I ask because your code seems in danger of targeting the wrong panel, which would be why you don't see the expected result.

Yet another question - how many colours can be selected/applied?

Yes, the blocks works as you described.

For the first two question, i use the one that is work, i just wanted to know why the other one does not, if i forgot this later and try that version for an other app.
No more panel i just named it to panels because it will be an IoT app and one canvas will translate to one panel. So just one list with lot of canvas. There will be 150. This is just a test version with the 20 canvas.
For the last question, the color will be selected from a color picker more precisely from a color wheel, whis gives RGB from its pixel, so there will be countless colors.

See this sample project before you go overboard ...

So, final list will be huge - Use Make a List rather than a Procedure, that might be where the bug is hidden. Take care to name each Canvas to match the Item Number of the List.

I thougt of this, and tried it as well before. Same result. i can use the working method its just test.

In the meantime i did some testing and figured out what is buggy. The problem is with the "for each item in list function".
list
It doesn't pass the indexes to other lists if they are in this function, only the first index is passed to other lists somehow.
So this doesn't work: only the first index passes so only the first element is changes.
list3

And this is work:
list2

So i think it is a bug. I don't know if i can change the topic type from help to bug or i have to open an other one for bug report?

From your example, show the contents of "global list" and "global list2".....

Here: The first picture is before changes, the second after changes.


I made a simple aia file.
list_test.aia (2.8 KB)
Of cource changing list2 elements by list1 element index has reason only with list1 elements condition checking.

OK, the way you are doing with your blocks will return the first item of the list because all the values are 0's (zeros). You have to use the "for each number" (in list) block to work with these lists. Less of a bug, more of a feature, buried in the annals of android/AI2 development.

It doesn't matter what is in them. It doesn't work if i fill them any number or text instead of zero.
"For each number has" a disadvantage if the list length is unknown, (addign, removing elements). Of course it also can be tracked by a variable. As i mentioned before, i can work with either the "for each number" or the version where i strore the index value in the list. It is just came out because first time i tried with this method.

Use length of list block to get length of list

Ok! Thank you for your time. I take this question as solved.
Still this is a bug. I leave you to decide if have to solve with time or not.
Thanks again.

Hi Zol

It is a bug in your code :slight_smile:

So long as list1 and list2 have matching indexes (as per my example), your code should be:

This if it's List2 you want to change
This

or This if it's List1 you want to change
orThis

No, it doesn't work. It doesn't accept item to index property. I've already tried that.
I correct it. It accept only f the elements are numbers.
But it is not working properly.

Oh sorry, my bad, that should be the index!

Index

Also, note that using Index, the loop is in index (numerical) order whereas using Item, there is no specific order.

I know this is work. We discussed it with TIM, few posts before.
And no problem with it, i can use it, as the other working method i mentioend.
Just as i said, logic dictates if i have a list, i check its elements for a condition then its index that i can use for other tasks, thats why it was my first try.
And we can say the two is almost identical in case of lists. The "for each item in list" is like "for each number" using "length of list" as you posted, but buggy. :slight_smile:
Anyway. Thank you for your ideas.