Text Output When Clicking a Button

Hi guys, I need to create a function for an app that when you click a button then the screen below the button should show text taken from a big library of texts. I am not sure if the content that appears should be random or not but I would like to know what should I do for both cases, random or according to the ranking on the library file.

From where you want to get your data ?

Depending on how you end up doing this, a funtion may not even be necessary.

If you’re just selecting a random entry, you can easily grab a random item from the data source by setting the label’s text to a shuffled item from that list.
Screenshot 2024-02-02 at 1.22.48 PM

Ranking based on the database would require some filtering. We have lots of previous topics about this and a lot of it just depends on which data source you have chosen.
https://community.thunkable.com/search?q=filter%20data%20source%20order:latest

either via an excell file or google sheet. I am mostly in favor of the excell file cause it would be better if the app could work without internet connection

I really have no idea how to make the necessary blocks for it to function before the block you show me

So you can use the internal table Data ( DOCS )to store data, I think you can copy paste your data from excel sheet.
Then you have to manage data from the database and show as you like , also randomly as Matt showed you .
Did you create your UI ? Did you store your data?

ok but first I need to create the function of making one content appear each time someone is clicking a button. Additionally what content appears must depend on what option the user chooses in the previous/initial screen.

I have made the design part with the components (buttons, text input component etc), what is missing is the functionality from the blocks screen

ok, You made some test? Have some blocks?
Where the user makes the choice (listview, checkbox, input text, swithc), you save the result inside a variable ?where you are storing all the data?
There are a lot of questions inside a litte “functionality” , you tried some code ?

Yes I have done the initial screen (both function and design) with a list where the user chooses an option. For data, I guess this should be done via an Excel file.

So I need to figure out what blocks I should use for the function I explained. To get a better idea check the blocks I used for the initial screen (the user chooses an option) and the main screen design where the text must be generated/shown when the user clicks the top button)


ok, when you rename a component add also the type in the name , ex. Bn_Option , Tb_Option , ListView_Name , so you know always the componet, to code fast and easy and also for debugging by other people :+1:

You don’t need a variable only for empty prompt, you can use the empty string in settings or with a code, explain better what you want to do. Why you want to show an empty list if you have a list of languages?

I don’t know how to get data from excel or if you can but as I said you there is an internal component

Show me as you saved data in the sheet, according to the database, you need a different way to get data

I am not sure what you mean “empty list”. Again I will have a library where hundreds of contents will be stored (probably with this internal table data you explained) and when the user clicks the button one of these hundreds of contents should appear on the screen (below that button as you see in the design). Also, suppose that there are 8 types of contents (50 contents for each type), and according to what option the user chose on the initial screen, this type of content should appear on the screen after clicking the generate content button.

Additionally don’t get confused about the languages you see in the blocks for the initial screen, this is not about translating or anything, just suppose that it says (a,b,d,c,etc options)

Sorry if this looks confusing but I am a beginner and this is my first attempt trying to create an app and kind of coding in general :slight_smile:

Thanks for the help!

And again if I don’t know how and where you will store all the contents I can’t help you I can only share you general information like the Docs of thunkable.

1- You tried to paste all data in the internal table, it works?
2- the 8 types are random in the database? If yes you need also a sort procedure
3- How you store data? A column for title, one for content and one with the text?
4- How many informations you have in the table (or you have to manage with the table)

Here a little example, don’t see the name but only the kind of blocks, to show you that there are a lot of way to get data.

  • The first example get a row from the database, I have to find the ID of the row searching the ID list at the same position of the clicked item in the listview, if data was stored right both in app and in the table.
  • The second get a single value, only a cell
  • The last get all the column named Book

You want a dropdown nemu?
You can add a text in the setting , fill the empty string at top and click add text items

image

then the code , if languages are showing save it in a variable (or do what you need ). If you use stored variable the value is saved inside app and you can get it when you will open the app next time

But neither do I know what is the best option to store the content, this is part of my question so…

  1. no I haven’t tried it since I need to know first what is the best option I have (I thought that I could just upload an excel file and thunkable would create the database from there, isn’t that possible?)

  2. I don’t know what you mean by random, the type of content depends on what option the user chooses on the initial screen

  3. practically only one column is needed, no need for a title. Also not sure what is the difference between content and text here. There will be only one column and each line will have a different text

  4. I explained above what the data will be. Also I guess that for each type I will use a different file or doc to keep it simple

Regarding the blocks you show I am not sure why this is about a list function. Shouldn’t the block be something like “when button - click” etc?

And for the simple list design, I am not sure why you are showing me this. I don’t ask how to make a list. I have already done the list for the initial screen. My question is only about the second screen as I showed you in the screenshot of the design

Lastly I will try to explain the function I need in a simple way supposing there are only 2 types of content to keep it simple:

So suppose that first, we have the initial screen where the user can pick on a list the option “A” or option “B”

After picking one of these 2 options the app opens the 2nd screen with the design I showed in the above screenshot. So if the user had picked option “A” in the initial screen then when they click the “Generate Poem” button, in the screen below the button should appear one of the following texts (suppose each line is a different text)

AAAAAAAAXXAAXA
AXAAXXAAXXAXXX
AAAXXXXAXXXXAA

If they had chosen the option “B” then one of the following should appear

BBXXXXXBBBBBBB
BXXXBBBXBBBBBX
BBBBBBXBXXXXXB

So what blocks are needed to program this simple function?

As I wrote you I don’t no about read from excel but I said you the best option I know. Paste and copy in data table . Test and you will know.

Probably I don’t understand what you mean with library and texts.

Ok

Probably is more easy a different column for type

Yes , I want to show you the purple block that get data from database

I’m more confused :thinking: make me a real example with real content .
A little column (4-5) items and a possible generate content

Thanks.

Why you are more confused,and what do you mean “real”? The actual final app will use hundreds or thousands of contents so there is no point showing these. If I know how to do this example then I will be able to figure out how to do a more complex function.

The example I mentioned seems clear to me so let me know what you don’t understand?

So you want to take something from your list and duplicate it randomly with an X, 14 times ? For 3 row ?

Who said anything about duplications and taking data from a list? I just just used the letter A in the 3 first lines of text in the above example to make it easy appear that these texts belong to type A and the same for the other 3 lines with be to show that they belong to type B.

If it’s easier for you here are other texts that you could consider for the above examble

Type A texts:
POEM 1
POEM 2
POEM 3

Type B texts:
POEM 4
POEM 5
POEM 6

You said taking from a big library of text, we speak about which kind of database you want to use too.
Anyway list is like a database, probably your will work with lists.
So you want items of the “same type” according to user choice. Yes you can with a simple random item of list or in list get if you don’t want it random .

The same type depends on how you will store data

OK so what blocks should I use for this example?