generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: How to use math.random?

Previous Thread :: Next Thread 
legokendall is not online. legokendall
Joined: 07 Aug 2010
Total Posts: 667
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 is online. 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 is not online. 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
legokendall is not online. legokendall
Joined: 07 Aug 2010
Total Posts: 667
26 Aug 2014 08:55 PM
@above I have no idea what that means XD
Report Abuse
Bobobob12 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image