|
| 18 Nov 2011 04:38 PM |
I have this chunk from a script for a scrollbar:
function scroll(x, y) if (mouseDown == true) then dist = y - script.Parent.Position.Y.Offset script.Parent.Position = UDim2.new(0, script.Parent.Position.X.Offset, 0, y - dist) end end
x and y are the 2D coordinates of the mouse. For some reason, the scrollbar's position ends up the same each time after calculation. Help? |
|
|
| Report Abuse |
|
|
gemerl20
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 4682 |
|
| |
|
|
| 18 Nov 2011 04:40 PM |
| No, the script is running fine, but there's a calculation error somewhere. |
|
|
| Report Abuse |
|
|
Merely
|
  |
| Joined: 07 Dec 2010 |
| Total Posts: 17266 |
|
|
| 18 Nov 2011 04:42 PM |
script.Parent.Position = UDim2.new(0, script.Parent.Position.X.Offset, 0, script.Parent.Position.Y.Offset + y)
Why not something simple like that? |
|
|
| Report Abuse |
|
|
|
| 18 Nov 2011 04:45 PM |
@Merely 1) Y is not relative to the position of the GUI 2) I created the relative position and did it like that, and it still didn't work. It moves, but it jumps around in huge increments. |
|
|
| Report Abuse |
|
|
Merely
|
  |
| Joined: 07 Dec 2010 |
| Total Posts: 17266 |
|
|
| 18 Nov 2011 04:45 PM |
| The problem is not Lua math. The problem is that you don't know what you're talking about. |
|
|
| Report Abuse |
|
|
Merely
|
  |
| Joined: 07 Dec 2010 |
| Total Posts: 17266 |
|
|
| 18 Nov 2011 04:46 PM |
function scroll(x, y) if (mouseDown == true) then script.Parent.Position = UDim2.new(0, x, 0, y) end end
There, I fixed it for you. |
|
|
| Report Abuse |
|
|
|
| 18 Nov 2011 04:48 PM |
@Mere 1) I only want it scrollable on the Y axis 2) When it's positioned, you have to remember it's positioned at the top left corner of the GUI |
|
|
| Report Abuse |
|
|
Merely
|
  |
| Joined: 07 Dec 2010 |
| Total Posts: 17266 |
|
|
| 18 Nov 2011 04:49 PM |
| Why do you have an x variable in there if you don't even use it? Is there another part of the function you haven't posted? |
|
|
| Report Abuse |
|
|
|
| 18 Nov 2011 04:51 PM |
| You have to, because this is a MouseMoved event. |
|
|
| Report Abuse |
|
|
|
| 18 Nov 2011 04:52 PM |
Whole script (edited a little):
mouseDown = false
function startScroll() mouseDown = true end
function scroll(x, y) if (mouseDown == true) then relativeY = y - script.Parent.Position.Y.Offset script.Parent.Position = UDim2.new(0, script.Parent.Position.X.Offset, 0, script.Parent.Position.Y.Offset - relativeY) end end
function endScroll() mouseDown = false end
script.Parent.MouseButton1Down:connect(startScroll) script.Parent.MouseMoved:connect(scroll) script.Parent.MouseButton1Up:connect(endScroll) script.Parent.MouseLeave:connect(endScroll) |
|
|
| Report Abuse |
|
|
Merely
|
  |
| Joined: 07 Dec 2010 |
| Total Posts: 17266 |
|
|
| 18 Nov 2011 04:55 PM |
function scroll(_, y) if (mouseDown == true) then script.Parent.Position = UDim2.new ( 0, script.Parent.Position.X.Offset, 0, script.Parent.Position.Y.Offset - (y - script.Parent.Position.Y.Offset) ) end end
I think your problem is here.
script.Parent.Position.Y.Offset - (y - script.Parent.Position.Y.Offset) |
|
|
| Report Abuse |
|
|
|
| 18 Nov 2011 04:56 PM |
| Why replace the x with _? It doesn't make a difference... |
|
|
| Report Abuse |
|
|
|
| 18 Nov 2011 04:56 PM |
| And what you did is basically the same thing I did :P |
|
|
| Report Abuse |
|
|
Merely
|
  |
| Joined: 07 Dec 2010 |
| Total Posts: 17266 |
|
|
| 18 Nov 2011 05:00 PM |
Look.
script.Parent.Position.Y.Offset - (y - script.Parent.Position.Y.Offset)
Tell me exactly what that means. |
|
|
| Report Abuse |
|
|
|
| 18 Nov 2011 05:01 PM |
| It means you just took my variable and squashed it into the UDim2 e.e |
|
|
| Report Abuse |
|
|
chaser26
|
  |
| Joined: 20 Aug 2010 |
| Total Posts: 2074 |
|
|
| 18 Nov 2011 05:03 PM |
| More details in that explanation |
|
|
| Report Abuse |
|
|