|
| 14 Sep 2016 06:21 AM |
| Is there a way to choose random out of a set of specific numbers? Please help me! |
|
|
| Report Abuse |
|
|
|
| 14 Sep 2016 06:28 AM |
local numberList = {1,2,3,4,5,6,7,8,9,11,45,51}
return numberlist[math.random(#numberList)] |
|
|
| Report Abuse |
|
|
| |
|
|
| 14 Sep 2016 06:34 AM |
| Wait. How would you test if it chose one of those numbers? |
|
|
| Report Abuse |
|
|
ManxFox
|
  |
| Joined: 12 Nov 2008 |
| Total Posts: 227 |
|
|
| 14 Sep 2016 06:41 AM |
it depends if you're running the script right off the bat in the server or if the random number is being chosen at different times, like for example the damage of a sword might be random
if the script is running as soon as the game starts, you need to have
math.randomseed(tick()) in the script before the number is chosen this ^ sets math.random's procedural sequence to make it completely random (you also only need it in one script in your game, once it is set in one script it works for them all)
see this: http://wiki.roblox.com/index.php?title=Random_numbers
to see if it is selecting a random number, the easiest way is to just use a print. so your finished script will want to look something like this:
math.randomseed(tick()) local numberList = {1,2,3,4,5,6,7,8,9,11,45,51} local chosenNum = numberlist[math.random(#numberList)]
print(chosenNum)
|
|
|
| Report Abuse |
|
|
|
| 14 Sep 2016 06:48 AM |
| Its being used for a random way to get a random amount of xp. Then a other script detects if the number is something then makes a certain mesh appear. But I don't wan to print it to the dev console. I want it to be detected in a if statement. |
|
|
| Report Abuse |
|
|
ManxFox
|
  |
| Joined: 12 Nov 2008 |
| Total Posts: 227 |
|
|
| 14 Sep 2016 07:03 AM |
test (forum broke and wouldn't let me respond)
|
|
|
| Report Abuse |
|
|
ManxFox
|
  |
| Joined: 12 Nov 2008 |
| Total Posts: 227 |
|
|
| 14 Sep 2016 07:07 AM |
Okay, the forum is being stupid and for whatever reason won't let me post what I was trying to post.
SO I'll try posting it in parts.
Part 1/3
if its from an enemy, you don't need to worry about the random.randomseed(tick()) thing. it may be easier to do it all in one script (in the enemies model) using functions:
|
|
|
| Report Abuse |
|
|
ManxFox
|
  |
| Joined: 12 Nov 2008 |
| Total Posts: 227 |
|
|
| 14 Sep 2016 07:09 AM |
| it won't let me post the rest of it...... "Bad Request" I tried messaging it to you and roblox threw up another error... ###### |
|
|
| Report Abuse |
|
|
ManxFox
|
  |
| Joined: 12 Nov 2008 |
| Total Posts: 227 |
|
|
| 14 Sep 2016 07:11 AM |
| ############################################## |
|
|
| Report Abuse |
|
|
ManxFox
|
  |
| Joined: 12 Nov 2008 |
| Total Posts: 227 |
|
|
| 14 Sep 2016 07:11 AM |
Oh my god.. ROBLOX needs to die.
Yeah, sorry man. I can't help you out because roblox literally will not let me send the solution to you..
|
|
|
| Report Abuse |
|
|
|
| 14 Sep 2016 09:29 AM |
local randomInteger = math.random(Min,Max) local randomNumber = Min + math.random()*(Max-Min) local randomIndex = A_Table[math.random(#A_Table)] |
|
|
| Report Abuse |
|
|
ManxFox
|
  |
| Joined: 12 Nov 2008 |
| Total Posts: 227 |
|
| |
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 14 Sep 2016 09:36 AM |
local nums = {1,2,3,4,5}
local ranNum = nums[math.random(1,#nums)]
if ranNum == 5 then --do something end
|
|
|
| Report Abuse |
|
|
| |
|
|
| 15 Sep 2016 07:25 AM |
--this one is better for ranges to prevent spamming numbers
local ranges = { {1,5,0.25}; --min,max,step {10,70,2}; }
function random(range) local rngind = math.random(#range) local rng = range[rngind] return math.random(rng[1]/rng[3],rng[2]/rng[3])*rng[3],rngind end
while true do print(random(ranges)) --returns random number in ranges and the index of it wait(0.4) end |
|
|
| Report Abuse |
|
|