|
| 11 Sep 2016 11:50 AM |
I need to write an algorithm to find the proper position for the gui, depending on its number.
Each row is 6 spaces, while the collum is infinite.
Example:
If gui number = 7, it would be the first gui on the 2nd row. But how would I write an algorithm to figure that out?
Not sure if I'm missing something really simple, but I've been dying over this for the past hour. x.x
~MightyDantheman |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
| |
|
|
| 11 Sep 2016 11:55 AM |
| #################################################################################################################################################### |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2016 01:21 PM |
What does this '%' do in that situation?
~MightyDantheman |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2016 01:24 PM |
google
https:// en. wikipedia. org/ wiki/ Modulo_operation
http:// www. mathsisfun. com/numbers /division-remainder. html |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 11 Sep 2016 01:29 PM |
You mean 6 columns, infinite rows.
for y = 1,6 do for x = 1,6 do gui.Size = UDim2.new(0,50,0,50) gui.Position = UDim2.new(0,x*50,0,y*50) end end
|
|
|
| Report Abuse |
|
|
| |
|
ParaText
|
  |
| Joined: 15 Aug 2016 |
| Total Posts: 799 |
|
|
| 11 Sep 2016 01:40 PM |
Modulus returns the remainder of integer division
|
|
|
| Report Abuse |
|
|
|
| 11 Sep 2016 01:44 PM |
What exactly is a module in this case? I saw on the wiki that one of the examples was '11 % 3 = 2'. What is it calculating for?
~MightyDantheman |
|
|
| Report Abuse |
|
|
ParaText
|
  |
| Joined: 15 Aug 2016 |
| Total Posts: 799 |
|
|
| 11 Sep 2016 01:46 PM |
It calculates the remainder in long division, specifically with integers. So 11/3 would have a whole number remainder of 2.
|
|
|
| Report Abuse |
|
|
|
| 11 Sep 2016 01:54 PM |
Oh oh, okay. Sorry, I didn't realize what you meant the first time.
~MightyDantheman |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2016 02:03 PM |
modulo works without integers, stop saying 'specific to integers' Also there is a function that does both steps in one: fmod |
|
|
| Report Abuse |
|
|
ParaText
|
  |
| Joined: 15 Aug 2016 |
| Total Posts: 799 |
|
|
| 11 Sep 2016 02:07 PM |
Why so hostile? :( I said specifically for integers because it's used on integers and returns an integer in most oop languages such as java. I never said it's limited to integers lol
|
|
|
| Report Abuse |
|
|
|
| 11 Sep 2016 02:08 PM |
Anyways, I'm still lost as to how to do this. I don't think I've really explained things well enough.
I have a GUI that is 100x100. I want each gui to move over 120p until they start a new row, in which case, it would move down 120.
I'd easily be able to do this if this was only one dimension, but with two, it really confuses me. -.-
I was going to do something like, for every 1 number, go down 120. But like I said, this is two dimensional, so it has to finish the row of 6 before it goes down.
Can someone explain how I'd do this?
~MightyDantheman |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2016 02:08 PM |
| local n,r = math.fmod(number,cols) |
|
|
| Report Abuse |
|
|
| |
|
ParaText
|
  |
| Joined: 15 Aug 2016 |
| Total Posts: 799 |
|
|
| 11 Sep 2016 02:10 PM |
Then why are you using modulus lol Just multiply the total number of gui objects in your frame and add the height of the gui object as the y value for the new gui object
|
|
|
| Report Abuse |
|
|
|
| 11 Sep 2016 02:10 PM |
for number,v in next,list do local x,y = math.fmod(number,cols) end |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2016 04:11 PM |
@ParaText
I want this to be continuous. It's kind of like an inventory if you will.
~MightyDantheman |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2016 04:18 PM |
Turns out, if I divide the number of the gui by 6 and around it down, I get what row it should be on. This feels a little make-shift, but it does it's job.
~MightyDantheman |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 11 Sep 2016 04:22 PM |
that's literally exactly what mine does aaaaaaaaaaaaaaaaaa
|
|
|
| Report Abuse |
|
|
|
| 11 Sep 2016 04:24 PM |
I know, I didn't exactly understand what you were doing. Forgive me. I haven't slept in a while. x.x
~MightyDantheman |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2016 05:33 PM |
I can't get this to work correctly for the life of me. It was cleaner before, but I kept messing around with it because it just wouldn't work.
Code:
local n = script.Parent:WaitForChild("SpriteNumber") wait(0.1) n.Value = game.Players.LocalPlayer.PlayerGui.ScreenGui.Sprites.SpriteCount.Value wait() script.Parent.Position = UDim2.new(0,((n.Value%5) - 1) * 120,0,math.floor(n.Value/5) * 120) wait() if script.Parent.Position.X.Offset < -100 then script.Parent.Position = UDim2.new(0,480,0,math.floor(n.Value/5) * 120) end
--//
Click 'Insert' a bunch and see what I mean:
https://www.roblox.com/games/499742175/Bloxly-2D-v0-1
~MightyDantheman |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2016 05:34 PM |
It skips the 5th one, then starts on the 5th one on all the other rows. Why?? x.x
~MightyDantheman |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2016 05:57 PM |
Welp, I'm gonna go to sleep. One last bump in hopes that someone will figure out why this is acting so strangely, by the time I wake up.
Side note, is this ROBLOX's fault or is it something in my code? I don't see how my code could cause this to happen, but knowing me... it probably is.. x.x
So yeah... bump.
~MightyDantheman |
|
|
| Report Abuse |
|
|