How do i take an item from my list in blocks and display that item in a label i've created?

Hi Thunkers!

I am a beginner working on one of my first projects and i came across a problem.
i made a list in blocks and the items include quotes, ig , and i wanted to take one of those items
and display it in the label i had created in my app but it randomly starts changing the text every second. it wont stay one quote and changes rapidly. how do i keep it one at a time?


the image above doesnt show the rapid changing and i cant record it either bu the code:
Screen Shot 2023-06-16 at 7.30.01 PM

Those blocks should only fire when you open the app or navigate back to that screen.

If it’s happening repeatedly and quickly, those blocks don’t explain that behavior.

Can you post a link to your project?

Are you testing in a browser or on a mobile device? If mobile, which device?

1 Like

Hi
i actually found out that i had a code for this in another part of my blocks and that was causing a bug so i deleted those and now its working fine
Thanks for trying to help tho!

1 Like

BUT you can help me by telling me why my label always shows undefined before i navigate to the list screen.
i want it to show a quote without needing to go there
heres a link:
https://x.thunkable.com/projects/6488896fb8100b197f171013/d06efc78-65a6-4a85-9cd2-599142a5e9ac/blocks

Which label on which screen?

the label thats on the screen i have shown

i have to press the see all quote/thoughts button b4 i can see quotes on that label

also its the home page screen

You can edit an existing post on the forums instead of adding so many short responses here.

Unfortunately, I can’t remix your project right now so I can’t look at it: Unble to remix project.

The label is undefined because you are asking it to display a list item from a list that hasn’t yet been defined. In this screenshot, app variable list display has no value so the list item assigned to app variable quote is undefined.

not only that - you have to switch the statement 1 and 2 inside the block - ie. you need to get a random index first before you can use it to obtain an item in the app_variable_list_display.

also, the code you have in the allthoughts screen, where you load the thoughts list with the correct set (according to time of day) should be placed in 3 places in home screen:

  1. during start
  2. inside your when_shuffle_click in the home screen.
  3. the same can be placed inside the when_allthoughts_clicked , but without the set_label statement - for you just want allthoughts screen to simply display what is the current thoughts list.

you can pack into a function that you can call in those 3 places.

2 Likes

i didnt quite understand what you ment here …
do you mind explaining this?

You are initializing app variable list display to an empty list on the “All thoughts” screen. But that screen comes after the “Home screen” screen. So on the Home screen where you are trying to get an item from that list, that’s going to fail. Even if it did work, it would be an empty list.

What are you expecting the value of these blocks to be?

Because you’re taking a random item from an empty list…

As an example, please set app variable list display to an actual value on the home screen. Then test and see if you still get undefined.

1 Like

Thanks! it worked and now it doesn’t show undefined. :grinning:

1 Like

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