Help with making code smaller and avoid repetition

Yes, I created beforehand in the designer. Wouldnt that be the same?

What happens if you use the button component directly here?

Taifun


This is a ListView.

It shows this error now:
erro

I see. The thing is in my app it needs to be buttons because i believe it would be better for user experience.


This is one of 3 screens where the buttons show up

Well, actually you just could do it using the already available advanced blocks without using an extension

Look for the advanced Button.Text block in the Any Button drawer

Taifun

So they would be okay with the times being out of order, and interspersed with empty slots?

Apparently this works almost perfectly. Thats what i did:


If i didnt set global button to every button in the .Initialize, it wouldnt work but inside it works, i also needed to select the global button with the index because otherwise it would give me an YaiList error.
The problem I have now is that the buttons are reversed... The 5th button have the first and 2nd value and so on.

1 Like

as I said in the beginning, it worrks perfectly, I tested dozens of times and it never missed a single number. I have the times received via bluetooth and it always receive the correct amount of numbers, which is 60. The thing is its really ugly and I didnt want to have that amount of blocks just to do this simple task lol, apart of probably hogging some performance

Try the for each loop from the end to the beginning...
From 5
To 1
By -1

Taifun

well, thats some weird magic... it still does it reversed, as if I didnt change the order lol

This thread hasn't yet included a pre-built component list.

Here's an example:

1 Like

Yes, sorry...
Use the previous loop and replace that number by 6 - number to get 5, 4, 3, 2, 1 while the loop counts up from 1 to 5

Taifun

1 Like

oh yeah, that fixed, it isnt reversed anymore. I dont know why didnt it work when I tried with only 1 button in the list but with 5 that I tested it works, its not reversed anymore, and i dont need to set global button to every button, even though this would be very convenient.

I tried like you did it and it works too. I'll see if I can use this way because I prefer this over the pre-built component list. Thanks alot you both. I'll try to implement this in my main project now and see if everything works. I can only know by monday if it works or not because the Arduino that we'll use is with my friend. Can this post stay open and I return monday or should I close this one and open another referencing this one?

Yes of course... don't worry
Taifun

1 Like

Hey, sorry for the delay, I really didnt have time before so I just tested it. It works perfectly, every button have the correct time and all the switches I implemented this type of code too is correct. Thank you guy very much for all the help. Im just having difficulty using tinyDB and storing the bluetooth ID in it. When I try to store the value, it just stores "true"?


Should I open another discussion?

I fixed, it was just the order i was storing the value. If i store before calling to connect the value is stored correctly

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.