robocu3
|
  |
| Joined: 13 Mar 2009 |
| Total Posts: 6485 |
|
|
| 17 Apr 2014 07:00 PM |
Do you think have everything jumbled together into one GUI or script is more efficient than having it spread out(to organize it), or what? I need opinions from people who have actually pulled off successful projects, I want to make something that doesn't run slow. :P -=Robo=- |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2014 07:01 PM |
| Organization and more scripts is nice |
|
|
| Report Abuse |
|
|
robocu3
|
  |
| Joined: 13 Mar 2009 |
| Total Posts: 6485 |
|
|
| 17 Apr 2014 07:03 PM |
So they shouldn't be all packed into one GUI or into a singular script...? That's good to know, I thought calling on a bunch of things at once slowed server speed. -=Robo=- |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2014 07:04 PM |
| Well, you have to be careful about some stuff, but having separate scripts is better than having a single script with thousands of lines of codes. |
|
|
| Report Abuse |
|
|
Mlatu
|
  |
| Joined: 01 Aug 2011 |
| Total Posts: 540 |
|
|
| 17 Apr 2014 07:05 PM |
| While it may be more efficient now to throw the whole thing into one script, it will benefit you in the long-run if you spread it out. It will help people understand how you script works, but, more importantly, it will help you remember how your script works. This is helpful in case you need to review it, update it, etc. |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2014 07:07 PM |
| Also, lets say you have everything in one script. If one error happens, the whole script breaks, which isnt good. |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2014 07:07 PM |
| i like spread out, but many uses of global functions. |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2014 07:25 PM |
you could have 10 scripts,and have it running something or 1 big script,making it run the same thing
1 big script errors:entire games fails
1 of the small scripts error,you can easily pinpoint it,and it wont stop everything else..
also,make sure you script is neat(so you can tell what it is,as well as others)
example1(bad):
script.Parent.Touched:connect(function(h) ypcall(function() h.Parent:BreakJoints() end) end)
example2(a LOT easier to read):
function OnTouched(thingThatTouched)
if thingThatTouched.Parent:FindFirstChild("Humanoid") then
thingThatTouched.Parent:BreakJoints()
end
end
script.Parent.Touched:connect(OnTouched) |
|
|
| Report Abuse |
|
|
robocu3
|
  |
| Joined: 13 Mar 2009 |
| Total Posts: 6485 |
|
|
| 17 Apr 2014 08:04 PM |
@island Even if it's easier to read, and it is, I only connect specific functions with events when absolutely necessary. Otherwise, I do; example; debounce = false script.Parent.Touched:connect(function(a) if debounce then return end debounce = true if a.Parent:FindFirstChild("Humanoid") then a.Parent.Humanoid:TakeDamage(100) wait(1) end end) -=Robo=- |
|
|
| Report Abuse |
|
|
0rka
|
  |
| Joined: 26 Dec 2013 |
| Total Posts: 1070 |
|
|
| 17 Apr 2014 08:12 PM |
| put it in a backpack object and use it to organize multiple scripts and such. |
|
|
| Report Abuse |
|
|
jode6543
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 5363 |
|
|
| 17 Apr 2014 08:22 PM |
Also, avoid having tons of small, duplicate scripts. For example, instead of putting this script:
debounce = false script.Parent.Touched:connect(function(a) if debounce then return end debounce = true if a.Parent:FindFirstChild("Humanoid") then a.Parent.Humanoid:TakeDamage(100) wait(1) end end)
In every lava brick in the map, group all the lava bricks into one model, and add one script into that model: for _,v in pairs(script.Parent:GetChildren()) do if v:IsA("BasePart") then local debounce = false v.Touched:connect(function(a) if debounce then return end debounce = true if a.Parent:FindFirstChild("Humanoid") then a.Parent.Humanoid:TakeDamage(100) wait(1) end end) end end
This way, if you want to change the lava brick so it, say, does 50 damage instead of 100, you only have to update one script instead of twenty.
~Jode |
|
|
| Report Abuse |
|
|
ToboboT
|
  |
| Joined: 25 Jun 2011 |
| Total Posts: 2385 |
|
|
| 17 Apr 2014 08:27 PM |
I do all of my stuff in backpack objects and I do pretty well
So ya a few scripts can be good
But I do like to write most of my code in one big main script where I reference ever other script. |
|
|
| Report Abuse |
|
|
robocu3
|
  |
| Joined: 13 Mar 2009 |
| Total Posts: 6485 |
|
|
| 17 Apr 2014 08:55 PM |
xD I already knew a lot of this stuff, guys, I'm not very "beginner"ish, but I appreciate the explanations. How does this code look to you? It's in a local script inside of a GUI, there's a larger script behind it but it handles less important things. function crouch() Character["Right Hip"].C1 = CFrame.new(0.5,-.5,0.5,0, 0, 1, 0, 1, 0, -1, -0, -0) Character["Left Hip"].C1 = CFrame.new(-0.5,-.5,0.5, -0, -0, -1, 0, 1, 0, 1, 0, 0) Character.Parent.HumanoidRootPart.RootJoint.C1 = CFrame.new(0, 1.5, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0) end
function cancelcrouch() Character["Right Hip"].C1 = CFrame.new(0.5, 1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0) Character["Left Hip"].C1 = CFrame.new(-0.5, 1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0) Character.Parent.HumanoidRootPart.RootJoint.C1 = CFrame.new(0, 0, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0) end
Mouse.KeyDown:connect(function(k) k:lower() if k == "c" then crouch() end end)
Mouse.KeyUp:connect(function(k) k:lower() if k == "c" then cancelcrouch() end end)
-=Robo=- |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 17 Apr 2014 09:00 PM |
| ^ Could be more "efficienized" and you have unneeded stuff |
|
|
| Report Abuse |
|
|
robocu3
|
  |
| Joined: 13 Mar 2009 |
| Total Posts: 6485 |
|
|
| 17 Apr 2014 09:08 PM |
Could you elaborate, in other words, tell me what could be improved on? -=Robo=- |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 17 Apr 2014 09:10 PM |
For one, making a reference to the following objects will make the script (negligibly) faster.
'Character["Right Hip"]' 'Character["Left Hip"]' 'Character.Parent.HumanoidRootPart.RootJoint.C1' --The HRP is in the character, unless you have one in workspace? 'k:lower()' --unneeded, KeyDown/Up event already does that.
And if you care that much about tiny speed improvements, you could make the KeyDown/Up events call a pre-made function, instead of creating and calling one each time |
|
|
| Report Abuse |
|
|
robocu3
|
  |
| Joined: 13 Mar 2009 |
| Total Posts: 6485 |
|
|
| 17 Apr 2014 09:15 PM |
isn't that what it's doing? and character is a variable that leads to the character's torso, i needed to get the parent(model) to get to the rootpart. -=Robo=- |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 17 Apr 2014 09:17 PM |
When you use anonymous functions like that, they are created and only exist while ran. So when you do something like:
part.Touched:connect(function(args) ... end)
vs
local function touched(args) ... end part.Touched(touched)
You do this in the first 1, it is simulating this: -create function -call function
In the second one it's doing something like this: -call function |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 17 Apr 2014 09:20 PM |
Actually, anonymous is not the right name in this case. Let's just say "temporary" since all functions in Lua are technically anonymous |
|
|
| Report Abuse |
|
|
jode6543
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 5363 |
|
|
| 17 Apr 2014 09:26 PM |
@Cnt I don't believe that is correct. Anonymous functions are just functions that aren't assigned to a variable; since Lua functions are first-class, they are managed as if they were variables (this includes GC). On the other hand, something like this would redefine the function every time:
function example() local function nestedFunction() --stuff end return nestedFunction() end
Since it goes out of scope the moment the function finishes execution. On the other hand, the :connect method still needs that function even after it calls it the first time, so it holds onto it and prevents it from going out of scope (and if it did go out of scope, the connect method would cease to work, not redefine the entire function again).
~Jode |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 17 Apr 2014 09:31 PM |
Yes I know what anonymous functions are, notice the reason why I said "temporary"
Anyway, you may be right but it does depend on how the connect method works and after doing some speed tests, it seemed to favor calling predefined function.
|
|
|
| Report Abuse |
|
|