|
| 26 Aug 2014 08:53 PM |
Hi! I'm trying to learn how to use math.random but not necessarily with numbers. You see I've looked it up on the wiki but all I can find is how to use it like math.random(1,100) or whatever, but I would like to know how to choose from words or whatever, like
print(math.random(pie,frog,pig,ect)
or something like that.
Mkay bai |
|
|
| Report Abuse |
|
|
Laedere
|
  |
| Joined: 17 Jun 2013 |
| Total Posts: 23601 |
|
|
| 26 Aug 2014 08:55 PM |
words = {"hi", "bye", "."} print(words[math.random(#words)]) |
|
|
| Report Abuse |
|
|
ROBOFROG
|
  |
| Joined: 04 Jan 2009 |
| Total Posts: 1519 |
|
|
| 26 Aug 2014 08:55 PM |
| You'd be better off using arrays/tables, and assigning a number value to each string in the list. |
|
|
| Report Abuse |
|
|
|
| 26 Aug 2014 08:55 PM |
| @above I have no idea what that means XD |
|
|
| Report Abuse |
|
|
Bobobob12
|
  |
| Joined: 23 Jan 2008 |
| Total Posts: 5350 |
|
|
| 26 Aug 2014 08:56 PM |
to use da words, you gotta make da linked table bro
local words = {"Dog", "Frog", "Bat", "Cat"}
print(words[math.random(1,#words)])
math.random only works to generate integers, which you can in turn use to access a particular element
written out longways it'd look a bit like this
local word = math.random(1, #words) --#words signifies the length of the table words, in this case 4
--Let's assume the math.random results in a 3, so word is 3
print(words[word]) --would output Bat, since bat is the third element of words |
|
|
| Report Abuse |
|
|
connor954
|
  |
| Joined: 24 Jul 2008 |
| Total Posts: 947 |
|
|
| 26 Aug 2014 09:02 PM |
local stuff = {thing,thing2,thing3}
while wait(2) do print(stuff[math.random(1,#stuff)]) end
~My home in the forums is Scripting Helpers...[Twitter: C-RBLX] |
|
|
| Report Abuse |
|
|