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: A quick question about UDim and UDim2?

Previous Thread :: Next Thread 
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
22 Oct 2012 01:51 PM
I've not tested this, and I can't as ROBLOX doesn't want to save (for some reason), and I want to know if this would work as a scroll script move down event like thing.
If you want to know, the hearacy (or however it's correctly spelled) is this:
ScreenGui
-TextButton
--ToggleScript(for toggling)
--ShopMenu
---Info
---Items
----TextButton
---ScrollFrame
----MoveUp event
-----Script
----MoveDown event
----Script
----ScrollBar
----DOWNbutton
-----script
----UPbutton
-----script


local increment = UDim.new(0.08, 0)
script.Parent.Event:connect(function()
local items = script.Parent.Parent.Parent.Items:GetChildren()
for i = 1, #items do
local pos = UDim.new(items[i].Position.Y)
items[i].Position = UDim2.new(0, 0, UDim.new(pos + increment))
end
end)

It is suppost to when the UP button is pressed get the children of Items, and for every item in Items, move it up by 0.08 Scale value.
Report Abuse
nominate10 is not online. nominate10
Joined: 20 May 2008
Total Posts: 2545
22 Oct 2012 01:57 PM
Firstly, you want UDim2.new, not UDim.new


Secondly, if you are trying to create a scrollbar, why not use RbxGui?
It lacks documentation, but take a look at it, try it out, and come back if you need more help.

http://wiki.roblox.com/index.php/Rbxgui

You'll want the createTrueScrollingFrame, which is similar to createScrollingFrame in terms of arguments but it only returns one object: the frame. Just place/position/design that at runtime from there and place things inside of it.
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
22 Oct 2012 01:58 PM
Nominate, I belive I am right with using UDim:

http://wiki.roblox.com/index.php/UDim
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
22 Oct 2012 01:59 PM
and Nominate, I tried using the Rbxgui version, but every time I tested it I got an error about a nil value near "RbxGui" (Or "Rbxgui", as I cannot remember what I tried)
Report Abuse
nominate10 is not online. nominate10
Joined: 20 May 2008
Total Posts: 2545
22 Oct 2012 02:07 PM
Concerning UDim2 and UDim:
If you take a look at the constructor for UDim, as shown on the wiki page, you'll notice it only takes 2 arguments.
UDim.new(Scale, Offset)

This only includes one axis, or one dimension; either x or y. UDim2 however, receives 4 arguments: scale and offset for 2 dimensions, hence the name. The Position and Size properties of GUI components all take UDim2 values.


Concerning Rbxgui: you have to import it first, like so:

RbxGui = assert(LoadLibrary("RbxGui"))

then use RbxGui.createTrueScrollingFrame
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
22 Oct 2012 02:10 PM
I know about RbxGui, but when I did EXACTLY that it errored with somthing like 'nil value'

About the UDim2 and UDim, If you read my script - i'm setting the Y value with a UDim:

items[i].Position = UDim2.new(0, 0, UDim.new(pos + increment))

Wait. I've discovered an even better way of doing it:

items[i].Position.Y = UDim.new(pos + increment)

Unless ROBLOX doesn't like me setting the Y value with a UDim.
Report Abuse
bob354293 is not online. bob354293
Joined: 26 Oct 2008
Total Posts: 2609
22 Oct 2012 02:10 PM
nominate. This is scripting helpers. Not direct to roblox wiki forum. Get out.
Report Abuse
nominate10 is not online. nominate10
Joined: 20 May 2008
Total Posts: 2545
22 Oct 2012 02:30 PM
@digpoe
UDim does not have a constructor that receives 3 arguments. UDim2.new(int scale, int offset) is the only constructor that exists for the .new method in UDim.
I work with GUIs a lot and trust me, you want UDim2.


As for you bob, I don't think I need to defend myself here, but I will anyway.
I help people by providing an explanation or example to help with their problem, and then follow it up with a link to a relevant wiki page for more information/sources. It is also to encourage people to use the wiki and that it usually has the information they're seeking. You? You go on other people's threads and try to shoo people away. You don't help anyone. That being said, have a nice day and good luck with your vehicle.
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
22 Oct 2012 02:39 PM
Nominate, I belive you do not understand what I am trying to achieve here.

I am trying to achieve a scroll system that when I press an UP button, everything scrolls up by increment (0.08) Scale position.

Now, here is my script that (probbably) doesn't work.

local increment = UDim.new(0.08, 0)
script.Parent.Event:connect(function()
local items = script.Parent.Parent.Parent.Items:GetChildren()
for i = 1, #items do
local pos = UDim.new(items[i].Position.Y)
items[i].Position = UDim2.new(0, 0, UDim.new(pos + increment))
end
end)

I'll explain it, line by line.
The first line sets the increment, which is 0.08 in Scale value.
The second line is a connection line, which fires the function when the BindableEvent is fired.
The third line is just getting the children of 'Items', for later use.
the fourth line is a simple for loop for every item in the items table.
The fifth line is a 'pos' variable, finding the Y position of item i in the items table.
The sixth line is setting the position of item i in the items table, to it's current Y position add the increment variable.
The seventh and eigth (I belive that's incorrectly spelled) lines are ending the current functions and loops.
Report Abuse
nominate10 is not online. nominate10
Joined: 20 May 2008
Total Posts: 2545
22 Oct 2012 03:04 PM
Ok, I understand a little better what you're trying to accomplish (I previously thought you were just wanting a scrollbar, like in the expanded leaderboard of the coregui). I also re-read the 6th line of your snippet and realized I skipped over parts of that line. Apologies for my ignorance, I've been trying to help swiftly so I guess I wasn't reading through carefully enough.

Try this, see if it works or not:

local increment = 0.08
script.Parent.Event:connect(function()
local items = script.Parent.Parent.Parent.Items:GetChildren()
for i = 1, #items do
items[i].Position = UDim2.new(0, 0, items[i].Position.Y.Scale+increment, 0)
end
end)

If that still doesn't work out for you, there might be an issue with your BindableEvent or something that prevents the event from firing.
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
22 Oct 2012 03:10 PM
I belive I have made a human error,

in the OP I said "UP button move everything UP", but adding onto a value on UDim2 moves them down.

Derp, hmm?
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
22 Oct 2012 03:12 PM
Ugh.....
This is too complicated now. My mind got itself into some form of paradox, as when you scroll up everything moves down and the oposite for scrolling up.
When scrolling down, you take from the value to make the topmost item appear as if it's going up and the rest of the page is coming up (as if you are scrolling down), and the oposite for scrolling up.
Report Abuse
nominate10 is not online. nominate10
Joined: 20 May 2008
Total Posts: 2545
22 Oct 2012 03:12 PM
Hah, I didn't even notice that either.
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
22 Oct 2012 03:17 PM
Right, I give up with the script I posted earlier. I'm going to need help with RbxGui. How would I make a scrolling frame like the one in the Player list, but listing items like "ITEM1", "ITEM2", "ITEM3", "ITEM4" and so on?
Report Abuse
nominate10 is not online. nominate10
Joined: 20 May 2008
Total Posts: 2545
22 Oct 2012 03:25 PM
rbxgui = assert(LoadLibrary("RbxGui")) -- this loads the library

scrollFrame, controlFrame = rbxgui:createTrueScrollingFrame() --create the objects
-- here we are going to simply match scrollFrame up with your items frame, using Items for the gui design and scrollFrame simply as a container
scrollFrame.Parent = items
scrollingFrame.Size = UDim2.new(1,0,1,0)
scrollingFrame.BackgroundTransparency = 1
controlFrame.Parent = scrollFrame -- tbh i'm not sure what the control frame does, but i put it in my scrollframe just in case


-- then just put all of your components into scrollFrame using lua code, and you should be set.
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