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 » Scripting Helpers
Home Search
 

Re: Lua math is being stupid...again...

Previous Thread :: Next Thread 
sk8ercool456 is not online. sk8ercool456
Joined: 24 Jan 2008
Total Posts: 1846
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 is not online. gemerl20
Joined: 27 Aug 2008
Total Posts: 4682
18 Nov 2011 04:40 PM
Is there an output?
Report Abuse
sk8ercool456 is not online. sk8ercool456
Joined: 24 Jan 2008
Total Posts: 1846
18 Nov 2011 04:40 PM
No, the script is running fine, but there's a calculation error somewhere.
Report Abuse
Merely is not online. 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
sk8ercool456 is not online. sk8ercool456
Joined: 24 Jan 2008
Total Posts: 1846
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 is not online. 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 is not online. 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
sk8ercool456 is not online. sk8ercool456
Joined: 24 Jan 2008
Total Posts: 1846
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 is not online. 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
sk8ercool456 is not online. sk8ercool456
Joined: 24 Jan 2008
Total Posts: 1846
18 Nov 2011 04:51 PM
You have to, because this is a MouseMoved event.
Report Abuse
sk8ercool456 is not online. sk8ercool456
Joined: 24 Jan 2008
Total Posts: 1846
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 is not online. 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
sk8ercool456 is not online. sk8ercool456
Joined: 24 Jan 2008
Total Posts: 1846
18 Nov 2011 04:56 PM
Why replace the x with _? It doesn't make a difference...
Report Abuse
sk8ercool456 is not online. sk8ercool456
Joined: 24 Jan 2008
Total Posts: 1846
18 Nov 2011 04:56 PM
And what you did is basically the same thing I did :P
Report Abuse
Merely is not online. 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
sk8ercool456 is not online. sk8ercool456
Joined: 24 Jan 2008
Total Posts: 1846
18 Nov 2011 05:01 PM
It means you just took my variable and squashed it into the UDim2 e.e
Report Abuse
chaser26 is not online. chaser26
Joined: 20 Aug 2010
Total Posts: 2074
18 Nov 2011 05:03 PM
More details in that explanation
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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