Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Common Roblox Ques?

Asked by 9 years ago

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?

Mod Edit: Removed Q4. Should be asked on its own. - urban

2 answers

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

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!

0
Thanks so much! I figured there was something that made those first values useful, never figured it out though! dragonkeeper467 453 — 9y
0
Glad I could help! Shawnyg 4330 — 9y
0
Scale is a percentage (in decimal form), just like Transparency or Reflectance. Therefore, just use a number between 0 and 1. Perci1 4988 — 9y
0
^ Yep! If you get into more advanced GUI work, you may go over 1, for nice animations. Shawnyg 4330 — 9y
Ad
Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

GUI Positions

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.


Events

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.

Functions

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.

3

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() dos (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.


  1. Not hardware pixels -- on high-dpi phones, 1 offset corresponds to more than one hardware pixel 

Answer this question