displaying any one information from the set of information provided

Hey
I am making an app wherein when the user opens the app, menu scene will appear and in the bottom of the scene i want to display facts of that particular app…i am writing 3-4 facts…whenever user opens that app, it should randomly select one of those facts and display on the screen.means, out of those 3-4 facts, any of the 1 fact should be displayed …i know about math.random but that is useful for numbers…not for sentences…any idea how to do it??
Thanks…

Hi,

you could make a table and add the variable that will display the fact, so something like: 

local facts = { 1 = "write fact 1" 2 = "write fact 2" 3 = "write fact 3" 4 = "write fact 4" } local factsTxt

Now you can call these facts by doing

facts.1 facts.2 ...

so now you could simply use math.random to randomize the numbers after the dot…

You could for example make a variable called “randomFactsNumber” and call the math.random function there.

local randomFactsNumber = math.random(1,4)

If you’d now do something like this:

factsTxt.text = facts.randomFactsNumber

You should be fine :slight_smile:

EDIT

if the previous piece of code is spitting some errors, try changing the last piece of code to this:

factsTxt.text = facts[randomFactsNumber]

I’m actually not 100% sure if the first suggestion would work so therefor this edit :slight_smile:

Thanks a lot for your help

How to place that fact in screen??
Should it be like this??
factsTxt.x = 400 (or any number)
factsTxt.y =. 400(or any number)

Hi,

that should work fine :slight_smile:

You should also give some info about the fontsize and font tho, I’m not sure what corona would do when these values are not provided.

Kind regards

Bram

Massive thanks

No worries!
Could you press the best answer button so people in the future with the same question will be able to find it easily?:slight_smile:
Kind regards

Sure!!:slight_smile::smiley::smiley:

Hi,

you could make a table and add the variable that will display the fact, so something like: 

local facts = { 1 = "write fact 1" 2 = "write fact 2" 3 = "write fact 3" 4 = "write fact 4" } local factsTxt

Now you can call these facts by doing

facts.1 facts.2 ...

so now you could simply use math.random to randomize the numbers after the dot…

You could for example make a variable called “randomFactsNumber” and call the math.random function there.

local randomFactsNumber = math.random(1,4)

If you’d now do something like this:

factsTxt.text = facts.randomFactsNumber

You should be fine :slight_smile:

EDIT

if the previous piece of code is spitting some errors, try changing the last piece of code to this:

factsTxt.text = facts[randomFactsNumber]

I’m actually not 100% sure if the first suggestion would work so therefor this edit :slight_smile:

Thanks a lot for your help

How to place that fact in screen??
Should it be like this??
factsTxt.x = 400 (or any number)
factsTxt.y =. 400(or any number)

Hi,

that should work fine :slight_smile:

You should also give some info about the fontsize and font tho, I’m not sure what corona would do when these values are not provided.

Kind regards

Bram

Massive thanks

No worries!
Could you press the best answer button so people in the future with the same question will be able to find it easily?:slight_smile:
Kind regards

Sure!!:slight_smile::smiley::smiley: