Hey I have a few questions posted below, if you answer 2 or more then ill consider your answer correct
1) I don't understand how gui positions work with different sized screens, is there a way you can have it so that a gui is always at a relative position on all screens?
2)How do events work, i know that a script is typically run from top to bottom, but if you add an event in to a script, how does that affect the way the script is run? If you could give me a brief overview of how things are run in roblox scripts and in what order that would be great!
3)[Opinion or biased(comment)] And I know this sort of depends on the project, but in general, is it easier or better to actually add objects to the workspace or is it better to add them and handle everything in a huge script?
1) Use the Scale for size and Position. In the GUI's Size/Position, it'll say the UDim2 value. Example: {6,0},{6,0} The 6's represent the scale.
2) If you add an event, it won't effect the way your script runs! The only thing that could interfere with the event, is a while loop that never ends.
3) Yeah, depends on the project. If I'm making a Map, a BillboardGui, or normally anything, I create it physically, then put it in ServerStorage.
Hope I helped! Comment if you have any questions!
First, ignore screens. Just think rectangles.
Any rectangle has a width and a height.
If we're measuring the width
and height
, in, say, pixels, We call the top-left (0, 0)
and the bottom-right (width, height)
.
Then the center will be half way in between: (width/2, height/2)
.
If we were to squash the box so it was now flatter, the (oldwidth/2, oldheight/2)
will not be the center of the new box. Further more, (0, height)
is now way past the bottom-left.
So this scheme isn't going to do well to keep track of things like centers or edges.
Let's measure points on the box in scale -- we call (0, 0)
the top-left, still, but the bottom-right will be (1, 1)
. Then the middle is (0.5, 0.5)
, no matter what size the rectangle is.
ROBLOX uses a value called UDim2 which combines these two measurements: Scale and Offset (in "pixels"1) -- you add the two components.
Chunks of scripts are always executed from top to bottom. But there are a few kinds of flow control in addition to functions which "skip" around. There are also multiple coroutines which can be "executing" in different places in the same script.
When Lua passes by a function definition, e.g.
print("first") function blah() print("second") end print("third")
The inside of the function does not run -- it simply defines what to do when the function blah
is called.
Later, when we call blah
, Lua remember where blah
is and jumps back to the inside of blah
(temporarily).
That's what happens with events -- you give ROBLOX a function, and ROBLOX then knows where to jump into when an event happens.
It depends. In general, one script will perform a little better, and will often be a little cleaner (though a bit longer).
The main reason it performs better is because many while wait() do
s (or similar constructs) will compete with one another if they're in separate scripts. There starts to be a lot of time taken just to hand off between the scripts. If there's only one, then that's much less of a problem.
Not hardware pixels -- on high-dpi phones, 1 offset corresponds to more than one hardware pixel ↩