Hi,
I'm trying to have 3 print statements and when a input is given it randomly chooses one of them and prints it.
Printing to the console will be enough.
My main issue is working with tables.{} (incase i want to increase the number later on).
I imagine it'd be something like:
1 | local printtable = {} -- Creation of table for print statements. |
1 2 3 4 5 | local printtable = {} ... some stuff to populate printtable print(printtable[math.random(#printtable)]) |
Thanks that's exactly it,
Thanks Robmiracle.
For anyone else who want to know, to populate your table i used.
1 2 3 | printtable[1] = "Print statement 1" printtable[2] = "print statement 2" printtable[3] = "Print statement 3" |
the easiest way to populate tables in lua is
local printtable = {
"Print Statement 1",
"Print Statement 2",
"Print Statement 3"
}
you can add more as you want without having to renumber the elements manually
cheers,
?:)
I chose the way i did it because it looked more uniform to me, it is just preferance afterall.
But you raise a valid point.
Thanks! ^^
views:1395 update:2011/10/19 8:59:29