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: Need help with a technique on how to find the closest GUI

Previous Thread :: Next Thread 
LawrenceWindsor is not online. LawrenceWindsor
Joined: 08 Mar 2015
Total Posts: 527
25 Jan 2017 11:47 AM
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA('TextLabel') then
v.ImageButton.MouseButton1Down:connect(function()
dragging = true
for _, tool in pairs(plr.Backpack:GetChildren()) do
if tool.TextureId == v.Image then
hum:EquipTool(tool)
end
end
end)
v.ImageButton.MouseButton1Up:connect(function()
if v.ImageButton.Position ~= UDim2.new(0,5,0,5) then
-- find the closest textlabel, parent the imagebutton to it, and set UDim2 to 0,5,0,5
end
end)
end
end

the imagebutton can be dragged, which allows it to be moved to a different slot in your toolbar. How would I find the closest textlabel?


Report Abuse
LawrenceWindsor is not online. LawrenceWindsor
Joined: 08 Mar 2015
Total Posts: 527
25 Jan 2017 02:40 PM
b


Report Abuse
LawrenceWindsor is not online. LawrenceWindsor
Joined: 08 Mar 2015
Total Posts: 527
25 Jan 2017 03:22 PM
ump


Report Abuse
LawrenceWindsor is not online. LawrenceWindsor
Joined: 08 Mar 2015
Total Posts: 527
25 Jan 2017 04:05 PM
I came up with this but it didn't seem to work correctly

v.ImageButton.DragStopped:connect(function(x, y)
local num = math.huge
local original = v
local ogButton = v.ImageButton
local new
for _, slot in pairs(script.Parent:GetChildren()) do
if slot:IsA('TextLabel') then
local slotpos = slot.AbsolutePosition.X
if slotpos and slotpos - x < num then
new = slot
end
end
end
if new:FindFirstChild('ImageButton') then
local swap = new.ImageButton
swap.Position = UDim2.new(0,5,0,5)
swap.Parent = original
end
ogButton.Parent = new
ogButton.Position = UDim2.new(0,5,0,5)
end)


Report Abuse
OAuth2 is not online. OAuth2
Joined: 27 Nov 2016
Total Posts: 751
25 Jan 2017 04:29 PM
local target, dist = nil, 0
for _, v in pairs(gui:GetChildren()) do
if v:IsA("GuiObject") then -- I'm not sure if this works tbh
if not target then
target, dist = v, (point.Position - v.Position).magnitude
else
if (point.Position - v.Position).magnitude < dist then
target, dist = v, (point.Position - v.Position).magnitude
end
end
end
end
-- Do stuff
Report Abuse
LawrenceWindsor is not online. LawrenceWindsor
Joined: 08 Mar 2015
Total Posts: 527
25 Jan 2017 04:39 PM
^ what..


Report Abuse
OAuth2 is not online. OAuth2
Joined: 27 Nov 2016
Total Posts: 751
25 Jan 2017 04:42 PM
Magnitude works for any positions.
Report Abuse
EXYZED is not online. EXYZED
Joined: 09 Nov 2013
Total Posts: 533
25 Jan 2017 05:56 PM
Indeed.
- Magnitude
Magnitude is a term used across mathematics that means several things. In vector theory, the magnitude of a vector is the length of a vector.

http://wiki.roblox.com/index.php?title=Magnitude

This is very useful in your circumstances.
Report Abuse
LawrenceWindsor is not online. LawrenceWindsor
Joined: 08 Mar 2015
Total Posts: 527
25 Jan 2017 06:11 PM
Magnitude does not work with gui objects


Report Abuse
EXYZED is not online. EXYZED
Joined: 09 Nov 2013
Total Posts: 533
25 Jan 2017 06:16 PM
Magnitude is math.
that math is Pythagoras.

Pythagoras is vector-wise, stated here in this scenario:
"
Commonly, in ROBLOX and other situations in need of finding the distance between two points, it is also referred to as the distance formula. ROBLOX has a special property for Vector3 and Vector2 values that does the math for finding the magnitude of the value for you. Here is how it can be indexed:
"

This math can be applied to POINTS, Specific to POSITION and SIZE. Does not mean that it cannot be applied to a GUI. GUI's also have vectors.
Report Abuse
EXYZED is not online. EXYZED
Joined: 09 Nov 2013
Total Posts: 533
25 Jan 2017 06:18 PM
Here is a perfect example of the usage of Magnitude in a 2D vector space.
http://wiki.roblox.com/index.php?title=2D_triangles

X.Y_Z (EXYZED)
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