| |
|
»
»
|
|
| |
Re: math.random help
|
|
|
xXRALXx
|
  |
| Joined: 12 Mar 2008 |
| Total Posts: 153 |
|
|
| 02 May 2014 01:59 AM |
for i = 1,50 do --do stuff
local gridItem = Instance.new("ImageButton") --stuff n stuff
pick = math.random(1, 27) if pick == 1 then gridItem.Position = UDim2.new(0,65,0,17) elseif pick == 2 then gridItem.Position = UDim2.new(0,128,0,17) elseif pick == 3 then ...
How do I make it so that when pick == 1, it wont choose pick == 1 again? I want to avoid gridItem(s) getting placed on the same position. |
|
|
| Report Abuse |
|
|
|
| 02 May 2014 02:06 AM |
Try this:
pick = math.random(1, 27) if pick == 1 and pick ~= 3 then gridItem.Position = UDim2.new(0,65,0,17) elseif pick == 2 and pick ~= 1 then gridItem.Position = UDim2.new(0,128,0,17) elseif pick == 3 and pick ~= 2 then
--Might work |
|
|
| Report Abuse |
|
|
|
| 02 May 2014 02:10 AM |
Before the loop:
local AvailablePicks={1,2,3,4,5,6,7,8....}
for i=1,50 do local pick=table.remove(AvailablePicks,math.random(#AvailablePicks))
Watch out though, if the number of "AvailablePicks" is less than 50, it will error. |
|
|
| Report Abuse |
|
|
Azarth
|
  |
| Joined: 17 Aug 2012 |
| Total Posts: 2760 |
|
|
| 02 May 2014 02:14 AM |
local folder = script.Parent
------------------ local rows = 10 local columns = 5 print("Total labels: "..rows*columns) ------------------ local X = 30 local Y = X ------------------ local gridColor = "Bright green" local outlineColor = "Institutional white" ------------------ local checker = true --Checkerboard? local checkerColor = "Really black" ------------------
local function create(instanc) return function(info) local new = Instance.new(instanc) for i,v in pairs(info) do new[i] = v end return new end end
for row = 1, rows,1 do for col = 1, columns, 1 do local color = (row+col)%2 == 0 and BrickColor.new(checkerColor) or not checker and BrickColor.new(checkerColor) or checker and BrickColor.new(gridColor) local b = create("Frame") { Size = UDim2.new(0,X,0,Y); BackgroundColor = color; Position = UDim2.new(0,row*X - X, 0, col*X - X); Parent = folder } wait() end end
--Azarth |
|
|
| Report Abuse |
|
|
xXRALXx
|
  |
| Joined: 12 Mar 2008 |
| Total Posts: 153 |
|
|
| 02 May 2014 02:19 AM |
Umm...?
Anyways, ignore the 'for i=1,50'
local AvailablePicks={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27} local pick=table.remove(AvailablePicks,math.random(#AvailablePicks)) pick = math.random(1, 27)-- Randomnize child.Position if pick == 1 then gridItem.Position = UDim2.new(0,65,0,17) elseif pick == 2 then gridItem.Position = UDim2.new(0,128,0,17) elseif pick == 3 then ...
I don't think I placed this correctly. Unless I have to tweak a little of it?
|
|
|
| Report Abuse |
|
|
Azarth
|
  |
| Joined: 17 Aug 2012 |
| Total Posts: 2760 |
|
|
| 02 May 2014 02:24 AM |
You want to make a GUI grid right?
http://www.roblox.com/Autoamted-GUI-grid-item?id=155633754 |
|
|
| Report Abuse |
|
|
xXRALXx
|
  |
| Joined: 12 Mar 2008 |
| Total Posts: 153 |
|
| |
|
|
| 02 May 2014 02:27 AM |
| The table should be outside of the loop. |
|
|
| Report Abuse |
|
|
xXRALXx
|
  |
| Joined: 12 Mar 2008 |
| Total Posts: 153 |
|
|
| 02 May 2014 02:53 AM |
| pick is already indexed, or should I replace it with the newer pick? I appreciate for your help Azarth, but I'm not sure if I can implement the GUI with what I need. Thanks though. |
|
|
| Report Abuse |
|
|
xXRALXx
|
  |
| Joined: 12 Mar 2008 |
| Total Posts: 153 |
|
| |
|
xXRALXx
|
  |
| Joined: 12 Mar 2008 |
| Total Posts: 153 |
|
|
| 02 May 2014 03:30 AM |
| The tables don't really help.. unless you could clarify exactly where to put/replace/blah blah. Just for the 1,27 part. |
|
|
| Report Abuse |
|
|
| |
|
xXRALXx
|
  |
| Joined: 12 Mar 2008 |
| Total Posts: 153 |
|
|
| 02 May 2014 03:36 AM |
Putting the tables outside the loop doesn't work.
pick = math.random(1, 27)-- Randomnize child.Position if pick == 1 then gridItem.Position = UDim2.new(0,65,0,17) elseif pick == 2 then gridItem.Position = UDim2.new(0,128,0,17) elseif pick == 3 then gridItem.Position = UDim2.new(0,191,0,17) elseif pick == 4 then gridItem.Position = UDim2.new(0,254,0,17) elseif pick == 5 then gridItem.Position = UDim2.new(0,317,0,17) elseif pick == 6 then gridItem.Position = UDim2.new(0,380,0,17) elseif pick == 7 then gridItem.Position = UDim2.new(0,443,0,17) elseif pick == 8 then gridItem.Position = UDim2.new(0,506,0,17) elseif pick == 9 then gridItem.Position = UDim2.new(0,569,0,17) elseif pick == 10 then gridItem.Position = UDim2.new(0,65,0,80) elseif pick == 11 then gridItem.Position = UDim2.new(0,128,0,80) elseif pick == 12 then gridItem.Position = UDim2.new(0,191,0,80) elseif pick == 13 then gridItem.Position = UDim2.new(0,254,0,80) elseif pick == 14 then gridItem.Position = UDim2.new(0,317,0,80) elseif pick == 15 then gridItem.Position = UDim2.new(0,380,0,80) elseif pick == 16 then gridItem.Position = UDim2.new(0,443,0,80) elseif pick == 17 then gridItem.Position = UDim2.new(0,506,0,80) elseif pick == 18 then gridItem.Position = UDim2.new(0,569,0,80) elseif pick == 19 then gridItem.Position = UDim2.new(0,65,0,143) elseif pick == 20 then gridItem.Position = UDim2.new(0,128,0,143) elseif pick == 21 then gridItem.Position = UDim2.new(0,191,0,143) elseif pick == 22 then gridItem.Position = UDim2.new(0,254,0,143) elseif pick == 23 then gridItem.Position = UDim2.new(0,317,0,143) elseif pick == 24 then gridItem.Position = UDim2.new(0,380,0,143) elseif pick == 25 then gridItem.Position = UDim2.new(0,443,0,143) elseif pick == 26 then gridItem.Position = UDim2.new(0,506,0,143) elseif pick == 27 then gridItem.Position = UDim2.new(0,569,0,143) end
So from here, I'm stuck on how it will select a position once |
|
|
| Report Abuse |
|
|
xXRALXx
|
  |
| Joined: 12 Mar 2008 |
| Total Posts: 153 |
|
| |
|
|
| 02 May 2014 03:41 AM |
local pick=math.random(27)-1 gridItem.Position=UDim2.new(0,65+63*(pick%9),0,17+63*math.floor(pick/9))
#mathftw |
|
|
| Report Abuse |
|
|
xXRALXx
|
  |
| Joined: 12 Mar 2008 |
| Total Posts: 153 |
|
|
| 02 May 2014 03:54 AM |
| Wow, nice! But I don't know if that'll mix in with the answer of my main question, since there's elseif's |
|
|
| Report Abuse |
|
|
|
| 02 May 2014 03:56 AM |
The code I posted is equivalent to
if pick == 1 then gridItem.Position = UDim2.new(0,65,0,17) elseif pick == 2 then gridItem.Position = UDim2.new(0,128,0,17) elseif pick == 3 then gridItem.Position = UDim2.new(0,191,0,17) elseif pick == 4 then gridItem.Position = UDim2.new(0,254,0,17) elseif pick == 5 then gridItem.Position = UDim2.new(0,317,0,17) elseif pick == 6 then gridItem.Position = UDim2.new(0,380,0,17) elseif pick == 7 then gridItem.Position = UDim2.new(0,443,0,17) elseif pick == 8 then gridItem.Position = UDim2.new(0,506,0,17) elseif pick == 9 then gridItem.Position = UDim2.new(0,569,0,17) elseif pick == 10 then gridItem.Position = UDim2.new(0,65,0,80) elseif pick == 11 then gridItem.Position = UDim2.new(0,128,0,80) elseif pick == 12 then gridItem.Position = UDim2.new(0,191,0,80) elseif pick == 13 then gridItem.Position = UDim2.new(0,254,0,80) elseif pick == 14 then gridItem.Position = UDim2.new(0,317,0,80) elseif pick == 15 then gridItem.Position = UDim2.new(0,380,0,80) elseif pick == 16 then gridItem.Position = UDim2.new(0,443,0,80) elseif pick == 17 then gridItem.Position = UDim2.new(0,506,0,80) elseif pick == 18 then gridItem.Position = UDim2.new(0,569,0,80) elseif pick == 19 then gridItem.Position = UDim2.new(0,65,0,143) elseif pick == 20 then gridItem.Position = UDim2.new(0,128,0,143) elseif pick == 21 then gridItem.Position = UDim2.new(0,191,0,143) elseif pick == 22 then gridItem.Position = UDim2.new(0,254,0,143) elseif pick == 23 then gridItem.Position = UDim2.new(0,317,0,143) elseif pick == 24 then gridItem.Position = UDim2.new(0,380,0,143) elseif pick == 25 then gridItem.Position = UDim2.new(0,443,0,143) elseif pick == 26 then gridItem.Position = UDim2.new(0,506,0,143) elseif pick == 27 then gridItem.Position = UDim2.new(0,569,0,143) end |
|
|
| Report Abuse |
|
|
xXRALXx
|
  |
| Joined: 12 Mar 2008 |
| Total Posts: 153 |
|
|
| 02 May 2014 03:58 AM |
| I know, I still need the answer to my MAIN question. First post. I'm stumped. |
|
|
| Report Abuse |
|
|
Azarth
|
  |
| Joined: 17 Aug 2012 |
| Total Posts: 2760 |
|
| |
|
|
| 02 May 2014 04:01 AM |
local AvailablePicks={} for i=1,27 do AvailablePicks[i]=i end
while #AvailablePicks>0 do --Make gridItem here local pick=table.remove(AvailablePicks,math.random(#AvailablePicks)) gridItem.Position=UDim2.new(0,65+63*(pick%9),0,17+63*math.floor(pick/9)) end |
|
|
| Report Abuse |
|
|
xXRALXx
|
  |
| Joined: 12 Mar 2008 |
| Total Posts: 153 |
|
|
| 02 May 2014 04:02 AM |
I know he did. :|
My main question and still can't figure it out;
pick = math.random(1, 27) if pick == 1 then gridItem.Position = UDim2.new(0,65,0,17) elseif pick == 2 then gridItem.Position = UDim2.new(0,128,0,17) elseif pick == 3 then ...
How do I make it so that when pick == 1, it wont choose pick == 1 again? I want to avoid gridItem(s) getting placed on the same position. |
|
|
| Report Abuse |
|
|
|
| 02 May 2014 04:04 AM |
| Whoopse, subtract 1 at the end of local pick=... |
|
|
| Report Abuse |
|
|
|
| 02 May 2014 04:10 AM |
x = {} --Add all the UDim2 x values here local pick = math.random(1, #x) gui.Position = UDim2.new(0, x[pick], 0, 0) |
|
|
| Report Abuse |
|
|
xXRALXx
|
  |
| Joined: 12 Mar 2008 |
| Total Posts: 153 |
|
|
| 02 May 2014 04:16 AM |
Hmm... the griditem still seems to overlap each other. Well, good night guys. I appreciate all the help you guys gave me. Here's the main code if anyone wants to waste their time fixing this junk. (This is the code unchanged.) Thank you guys again.
CODE: local ArmorData = game.Lighting.ArmorData local items = ArmorData:GetChildren() local StoreChestData = game.Lighting.ChestData local NameValue = script.ChestNameValue local ASSET_URL = "http://www.roblox.com/asset/?id="
local function GenerateChests() for i = 1,50 do NameValue.Value = NameValue.Value + 1 --Names Chests 1-50 local ChestGui = Instance.new("ScreenGui") ChestGui.Name = "Chest_" .. NameValue.Value ChestGui.Parent = StoreChestData
local Frame = Instance.new("Frame") Frame.Position = UDim2.new(0,365,0,150) Frame.BackgroundTransparency = 1 Frame.Parent = ChestGui local BackImage1 = Instance.new("ImageLabel") BackImage1.Image = ASSET_URL .. 154118615 BackImage1.Size = UDim2.new(0,224,0,224) BackImage1.Position = UDim2.new(0,30,0,0) BackImage1.BackgroundTransparency = 1 BackImage1.ZIndex = 3 BackImage1.Parent = Frame
local BackImage2 = Instance.new("ImageLabel") BackImage2.Image = ASSET_URL .. 154118622 BackImage2.Size = UDim2.new(0,224,0,224) BackImage2.Position = UDim2.new(0,236,0,0) BackImage2.BackgroundTransparency = 1 BackImage2.ZIndex = 3 BackImage2.Parent = Frame
local BackImage3 = Instance.new("ImageLabel") BackImage3.Image = ASSET_URL .. 154118630 BackImage3.Size = UDim2.new(0,224,0,224) BackImage3.Position = UDim2.new(0,442,0,0) BackImage3.BackgroundTransparency = 1 BackImage3.ZIndex = 3 BackImage3.Parent = Frame
local child = ArmorData:GetChildren() local RandomItems = {} for x = 1, math.random(1, 6) do table.insert(RandomItems, child[math.random(1, #child)]) end for _, v in pairs (RandomItems) do
local thumbnailObject = v:FindFirstChild('Thumbnail') if thumbnailObject then local gridItem = Instance.new("ImageButton") gridItem.Name = v.Name gridItem.ZIndex = 4 gridItem.BackgroundTransparency = 1 gridItem.Size = UDim2.new(0, 60, 0, 60) gridItem.Image = ASSET_URL .. thumbnailObject.Value pick = math.random(1, 27) if pick == 1 then gridItem.Position = UDim2.new(0,65,0,17) elseif pick == 2 then gridItem.Position = UDim2.new(0,128,0,17) elseif pick == 3 then gridItem.Position = UDim2.new(0,191,0,17) elseif pick == 4 then gridItem.Position = UDim2.new(0,254,0,17) elseif pick == 5 then gridItem.Position = UDim2.new(0,317,0,17) elseif pick == 6 then gridItem.Position = UDim2.new(0,380,0,17) elseif pick == 7 then gridItem.Position = UDim2.new(0,443,0,17) elseif pick == 8 then gridItem.Position = UDim2.new(0,506,0,17) elseif pick == 9 then gridItem.Position = UDim2.new(0,569,0,17) elseif pick == 10 then gridItem.Position = UDim2.new(0,65,0,80) elseif pick == 11 then gridItem.Position = UDim2.new(0,128,0,80) elseif pick == 12 then gridItem.Position = UDim2.new(0,191,0,80) elseif pick == 13 then gridItem.Position = UDim2.new(0,254,0,80) elseif pick == 14 then gridItem.Position = UDim2.new(0,317,0,80) elseif pick == 15 then gridItem.Position = UDim2.new(0,380,0,80) elseif pick == 16 then gridItem.Position = UDim2.new(0,443,0,80) elseif pick == 17 then gridItem.Position = UDim2.new(0,506,0,80) elseif pick == 18 then gridItem.Position = UDim2.new(0,569,0,80) elseif pick == 19 then gridItem.Position = UDim2.new(0,65,0,143) elseif pick == 20 then gridItem.Position = UDim2.new(0,128,0,143) elseif pick == 21 then gridItem.Position = UDim2.new(0,191,0,143) elseif pick == 22 then gridItem.Position = UDim2.new(0,254,0,143) elseif pick == 23 then gridItem.Position = UDim2.new(0,317,0,143) elseif pick == 24 then gridItem.Position = UDim2.new(0,380,0,143) elseif pick == 25 then gridItem.Position = UDim2.new(0,443,0,143) elseif pick == 26 then gridItem.Position = UDim2.new(0,506,0,143) elseif pick == 27 then gridItem.Position = UDim2.new(0,569,0,143) end gridItem.Parent = Frame end end end end wait(10) local Playas = game.Players:GetChildren() for p = 1, #Playas do for _, child in pairs(StoreChestData:GetChildren()) do if child:IsA('ScreenGui') then child:Clone().Parent = Playas[p].PlayerGui.ChestGui end end for _, child in pairs(StoreChestData:GetChildren()) do if child:IsA('ScreenGui') then child:Destroy() NameValue.Value = 0 end end end
GenerateChests() |
|
|
| Report Abuse |
|
|
|
| 02 May 2014 04:19 AM |
Put this:
local AvailablePicks={} for i=1,27 do AvailablePicks[i]=i end
just above this line:
for _, v in pairs (RandomItems) do
and replace this:
pick = math.random(1, 27) if pick == 1 then gridItem.Position = UDim2.new(0,65,0,17) elseif pick == 2 then gridItem.Position = UDim2.new(0,128,0,17) elseif pick == 3 then gridItem.Position = UDim2.new(0,191,0,17) elseif pick == 4 then gridItem.Position = UDim2.new(0,254,0,17) elseif pick == 5 then gridItem.Position = UDim2.new(0,317,0,17) elseif pick == 6 then gridItem.Position = UDim2.new(0,380,0,17) elseif pick == 7 then gridItem.Position = UDim2.new(0,443,0,17) elseif pick == 8 then gridItem.Position = UDim2.new(0,506,0,17) elseif pick == 9 then gridItem.Position = UDim2.new(0,569,0,17) elseif pick == 10 then gridItem.Position = UDim2.new(0,65,0,80) elseif pick == 11 then gridItem.Position = UDim2.new(0,128,0,80) elseif pick == 12 then gridItem.Position = UDim2.new(0,191,0,80) elseif pick == 13 then gridItem.Position = UDim2.new(0,254,0,80) elseif pick == 14 then gridItem.Position = UDim2.new(0,317,0,80) elseif pick == 15 then gridItem.Position = UDim2.new(0,380,0,80) elseif pick == 16 then gridItem.Position = UDim2.new(0,443,0,80) elseif pick == 17 then gridItem.Position = UDim2.new(0,506,0,80) elseif pick == 18 then gridItem.Position = UDim2.new(0,569,0,80) elseif pick == 19 then gridItem.Position = UDim2.new(0,65,0,143) elseif pick == 20 then gridItem.Position = UDim2.new(0,128,0,143) elseif pick == 21 then gridItem.Position = UDim2.new(0,191,0,143) elseif pick == 22 then gridItem.Position = UDim2.new(0,254,0,143) elseif pick == 23 then gridItem.Position = UDim2.new(0,317,0,143) elseif pick == 24 then gridItem.Position = UDim2.new(0,380,0,143) elseif pick == 25 then gridItem.Position = UDim2.new(0,443,0,143) elseif pick == 26 then gridItem.Position = UDim2.new(0,506,0,143) elseif pick == 27 then gridItem.Position = UDim2.new(0,569,0,143) end
with this:
local pick=table.remove(AvailablePicks,math.random(#AvailablePicks))-1 gridItem.Position=UDim2.new(0,65+63*(pick%9),0,17+63*math.floor(pick/9)) |
|
|
| Report Abuse |
|
|
|
| |
|
|
| |
|
»
»
|
|
|
|
|