How to get a random text to be pulled out of a data source, then displayed on the screen

So In my app I want there to be a feature where every set amount of time a random “challenge” is displayed on the screen. I was wondering how I could do this in a way that I can put in the “challenges” beforehand, I think I could use a data source somehow, but I am not completely sure.

Any help would be greatly appreciated.

Yes, add each challenge as a separate row in your data source. Set a variable to the list of values from one column of the data source.

Then, when you want to select a random challenge, get and remove a random item from the list and set a variable to it. Display the variable in a label.

There are some examples here:

Ok, thanks I will check that out :slight_smile:

Before I try what you have said above, does this spreadsheet look like what you had in mind?
*The Challenges are just examples, they don’t matter what they are.


Ok I have looked at the links you have sent me and this is what I have so far, does anything need changing?

Whilst I wait for you to reply I will test it out, Again, Many Thanks Levi

So It almost works, When I click the button it changes from “Your Challenge is…” to " null" then I click it again and it shows all of the challenges at once in 1 long list, Here are some photos:

They go in order from the bottom to the top, Your Challenge is…, null, Do 50 situps ect.

The list of values block is already a list. When you add a (gear) list block in front of it, you make a list of lists which is not something you generally should do. Please remove the (gear) list block and see if that helps.

Ok, Thanks I will try that.

It works, but sometimes because the challenge is random the same challenge theoretically could be done twice in a row, so is there a way to make it so it does not repeat the perivous challenge?

Many Thanks, Levi

Yes, that’s why I mentioned the get and remove block before.

Instead of getting a random item from the list, choose a random number from 1 to the length of the list. Set a variable to that random number value. Then, get and remove the item at index [random number variable].

Can you show me how to do that in blocks, sorry I can’t find any of the blocks you have stated above, Thanks :slight_smile:

The get and remove block is in this block’s drop-down menu:


But I just realized that that will only work (I think) with a dedicated list. Not with a data source. So you’ll need to do this instead:

You should be aware that there is a bug that sometimes causes the Get Value block to not work. In that case, you’ll need to do this instead:

It’s probably safer to just go with that to start with.

Cool thanks, I will try that out.

It works slightly better, about one in 12 times I click the button the challenge result will be the same as before so I would have to press the button twice, but unless there’s an easy way to fix it, then it should not be too much of a problem.

Many Thanks, Levi.

I tried both of the screen shot you sent me above the both feel better than what I had, and both of your screenshots felt the same.

If you choose a row number and then delete it, you will never have a repeat.

You can check the error block value to see if there was a problem deleting rows but I doubt that’s the cause.

Ok, I will check.

What I mean is I would still like them to eventually cycle thought randomly like what I had at the start except not to randomly select the same challenge from the data source twice in a row, because later on I don’t what to be having to type out all the challenges in my spreadsheet after every time someone uses my app.

Many Thanks, Levi.

If this is too hard to do no worries, I would just like to get everything working perfectly before I move on to other elements of my app. :slight_smile: