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 » Scripters
Home Search
 

Re: Algorithm Help?

Previous Thread :: Next Thread 
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
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 is not online. Kodran
Joined: 15 Aug 2013
Total Posts: 5330
11 Sep 2016 11:52 AM
x=n%6
y=math.floor(n/6)




Report Abuse
batistapowerbonbtla is not online. batistapowerbonbtla
Joined: 16 Dec 2011
Total Posts: 2203
11 Sep 2016 11:55 AM
####################################################################################################################################################
Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
11 Sep 2016 01:21 PM
What does this '%' do in that situation?


~MightyDantheman
Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
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 is not online. 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
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
11 Sep 2016 01:30 PM
yeah


~MightyDantheman
Report Abuse
ParaText is not online. ParaText
Joined: 15 Aug 2016
Total Posts: 799
11 Sep 2016 01:40 PM
Modulus returns the remainder of integer division


Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
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 is not online. 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
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
11 Sep 2016 01:54 PM
Oh oh, okay. Sorry, I didn't realize what you meant the first time.


~MightyDantheman
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
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 is not online. 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
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
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
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
11 Sep 2016 02:08 PM
local n,r = math.fmod(number,cols)
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
11 Sep 2016 02:09 PM
i'm not being hostile?
Report Abuse
ParaText is not online. 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
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
11 Sep 2016 02:10 PM
for number,v in next,list do
local x,y = math.fmod(number,cols)
end
Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
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
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
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 is not online. Kodran
Joined: 15 Aug 2013
Total Posts: 5330
11 Sep 2016 04:22 PM
that's literally exactly what mine does aaaaaaaaaaaaaaaaaa


Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
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
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
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
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
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
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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