| |
|
»
»
|
|
| |
Re: Coding Etiquette
|
|
|
sasracer
|
  |
| Joined: 22 May 2008 |
| Total Posts: 683 |
|
|
| 16 Aug 2011 11:57 AM |
| Personally, I like to use comments when I remember, and I almost always indent my scripts. Anything you guys do to help you understand your code better? |
|
|
| Report Abuse |
|
|
superior
|
  |
| Joined: 13 Apr 2008 |
| Total Posts: 1662 |
|
|
| 16 Aug 2011 12:04 PM |
| Sometimes space each line out. Only if there is something wrong in a certain part of the script. Other than that, I like to indent, and use comments as well. |
|
|
| Report Abuse |
|
|
sdfgw
|
  |
 |
| Joined: 08 Jan 2009 |
| Total Posts: 41681 |
|
|
| 16 Aug 2011 12:08 PM |
Indenting is obligatory IMO, I never comment because I don't care
I worry more about the flow of scripts :u |
|
|
| Report Abuse |
|
|
superior
|
  |
| Joined: 13 Apr 2008 |
| Total Posts: 1662 |
|
|
| 16 Aug 2011 12:11 PM |
Haha: "I never comment, because I don't care." That made me laugh. :P |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2011 12:13 PM |
I only comment if I can't visualize what I'm trying to do. This happens a lot when I'm using multidimensional arrays.
(°3°) Hai |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2011 12:14 PM |
Indenting is a must for me. Don't really comment unless it's meant for editing. I space out arithmetic;
if value < = anothervalue then value * anothervalue end |
|
|
| Report Abuse |
|
|
superior
|
  |
| Joined: 13 Apr 2008 |
| Total Posts: 1662 |
|
|
| 16 Aug 2011 12:16 PM |
Thats another thing I do, I forgot. I space everything out.
if this == this then
cframe.new(0, 0, 0)
if 1 + 2 = 3 then |
|
|
| Report Abuse |
|
|
sdfgw
|
  |
 |
| Joined: 08 Jan 2009 |
| Total Posts: 41681 |
|
|
| 16 Aug 2011 12:17 PM |
| I only ever leave gaps between major chucks, and if it's inside a function, I never put blank lines in. |
|
|
| Report Abuse |
|
|
sasracer
|
  |
| Joined: 22 May 2008 |
| Total Posts: 683 |
|
|
| 16 Aug 2011 12:25 PM |
@ sdfgw
Yeah, same. I always have gaps inbetween chunks of code, but rarely in the middle of one. |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2011 12:51 PM |
I sort my variable declarations from my content. Sometimes, I even split variable declaration into separate sections that handle a specific thing.
I also name my functions to describe what they do, no matter the length. I'd rather use 'updateLineNumsAndLines' than 'x' as my function. |
|
|
| Report Abuse |
|
|
sdfgw
|
  |
 |
| Joined: 08 Jan 2009 |
| Total Posts: 41681 |
|
|
| 16 Aug 2011 01:03 PM |
@Agent:
I'd like to compare scripts based on what you just said. Uh, here's the last script I edited
s = script.Parent a = s.Amred am = s.Ammo tcc = "BLU" cct = "RED" if a.Value then tcc = "RED" cct = "BLU" end l = s.Level print(l.Value) h = s.Health m = s.Main while l.Value == 0 do wait() end f = s.Above.FocusPocus g = f.BodyGyro gungun = nil local z = false
function endy(dir, pos) local p = Instance.new("Part") p.Name = "SENNARDUST" p.Position = pos p.CanCollide = false p.formFactor = "Plate" p.Size = Vector3.new(1, 0.4, 1) p.Velocity = Vector3.new(dir.x+math.random(-5, 5)/15, -1.5, dir.z+math.random(-5, 5)/15)*-10 if z then p.BrickColor = BrickColor.new("Bright red") else p.BrickColor = BrickColor.new("Bright yellow") end p.Parent = game.Workspace.Debris end
function fire(g, xxx) z = false if l.Value > 1 then if xxx==nil then xxx = shared.getId() fire(g, xxx) gungun = s.Level2.LTurret else gungun = s.Level2.RTurret end else gungun = s.Level1.Gun xxx = shared.getId() end local dir = (g.Position-gungun.Position).unit local inter, pos = game.Workspace:FindPartOnRay(Ray.new(gungun.Position+dir*3, dir*100), game.Workspace.Debris) if inter~=nil then print(inter.Name, inter.Parent.Name) if am.Value > 0 and g.Parent == inter.Parent then local id = tcc .. "SEN" .. tostring(shared.getId()) if g.Parent.Humanoid.Health > 0 then z = true shared.tag(g.Parent.Humanoid, string.sub(s, 7), "Sentry") shared.damage(g.Parent.Humanoid, 16, pos, id, false) endy(dir, pos) end end end end
function check() local r = 100 local t = nil for i, v in pairs(game.Workspace:GetChildren()) do if v:findFirstChild("Humanoid") ~= nil and v.Humanoid:findFirstChild("Amred") and v:findFirstChild("Torso")~=nil then local p = game.Players:GetPlayerFromCharacter(v) if p~=nil then tc = p.TeamColor==BrickColor.new("Bright red") else tc = not a.Value end if tc~=a.Value and v.Humanoid.Amred.Value~=a.Value and v.Humanoid.Health > 0 then local dd = (v.Torso.Position-m.Position).magnitude if dd < r then r = dd t = v.Torso end end end end return t end whom = nil meth = nil h.ChildAdded:connect(function (v) if v.className == "StringValue" then whom = v.Name meth = v.Value end end) while h.Value > 0 do wait(0.1) local now = check() if now~=nil then local lv = (now.Position-f.Position).unit g.cframe = CFrame.new(f.Position, f.Position-lv) fire(now) s.Level1.Gun.Mesh.Scale = Vector3.new(0.2, 0.2, 0.8) wait(0.15) s.Level1.Gun.Mesh.Scale = Vector3.new(0.2, 0.2, 1) else g.cframe = g.cframe * CFrame.Angles(0, math.pi/20, 0) wait(0.15) end end
local what = false local assist = {} for i, v in pairs(h:GetChildren()) do if v.className == "StringValue" then if v.Name == whom then what = true else assist[#assist+1] = v.Name end end end if what then print("pwnt by " .. whom) print("also guess what?", string.sub(s.Name, 7)) shared.registerSEN(whom, string.sub(s.Name, 7), assist, meth) else shared.registerSENNC(string.sub(s.Name, 7)) end
for i, v in pairs(s:GetChildren()) do if v.className == "Model" then for _, q in pairs(v:GetChildren()) do q.Anchored = false q.CanCollide = true if q.Name == "FocusPocus" then script.NOPE:play() q.BodyPosition:remove() q.BodyGyro:remove() end end else if v~=script then v:remove() end end end s:BreakJoints() wait(5) s:remove()
LOL 1 LETTER VARIABLES FOR NEARLY EVERYTHING |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2011 01:05 PM |
My plugin code. Ignore the comments, I've yet to take them out. 8D Also, it's all tabbed in the original script.
local on = false local scriptType = "LocalScript" local editor
--------------- --PLUGIN SETUP- ---------------
--make internal representation of plugin (needed to call functions like CreateToolbar() and Activate()) self = PluginManager():CreatePlugin()
--Deactivation event is sent when another plugin calls Activate(), turn off when Deactivation event is received self.Deactivation:connect(function() Off() end)
--make a new toolbar, "Time" is the name of it, if another plugin also uses a toolbar named "Time" they will both create buttons on the same one toolbar = self:CreateToolbar("InsertScript")
--make a button on the toolbar, the first parameter is the text on the button, second is the tooltip, and last is the icon toolbarbutton = toolbar:CreateButton("", "Insert Script", "newscript.png")
--make button turn plugin on and off toolbarbutton.Click:connect(function() if on then Off() else On() end end)
function On() editor.Visible = true on = true end
function Off() editor.Visible = false on = false Source_ = { "print 'Hello, world!'" } end
----------------------------- --CREATE SCRIPT CONTENT GUI-- ----------------------------- function newColor(r, g, b) return Color3.new(r/255, g/255, b/255) end
function tableconcat(Table, delimiter) local r = "" local End = 0 for _, v in pairs(Table) do End = _ end for i = 1, End do r = r..(Table[i]~=nil and Table[i] or "")..delimiter end return r end
local Source_ = { "print 'Hello, world!'" } local Source = setmetatable({}, {__index = Source_, __newindex = function(t, k, v) if (v~=nil and v~="") then rawset(Source_, k, v) else end end}) local S1, S2;
local g = Instance.new("ScreenGui", game:GetService("CoreGui"))
editor = Instance.new("Frame", g) local index = Instance.new("IntValue", editor) local selected = Instance.new("IntValue", editor) local numlines = Instance.new("IntValue", editor) editor.Name = "Editor" editor.BackgroundColor3 = Color3.new(0,0,0) editor.BackgroundTransparency = 0.7 editor.BorderSizePixel = 0 editor.Position = UDim2.new(0.5, -300, 0.5, -250) editor.Size = UDim2.new(0, 600, 0, 500) editor.Visible = false index.Value = 1 index.Name = "LineIndex" numlines.Value = 1 numlines.Name = "NumLines" selected.Name = "SelectedLine"
local title = Instance.new("Frame", editor) local titleText = Instance.new("TextLabel", title) title.Name = "Title" title.BackgroundTransparency = 0.7 title.Size = UDim2.new(1, -1, 0, 20) titleText.BackgroundTransparency = 1 titleText.FontSize = Enum.FontSize.Size14 titleText.Size = UDim2.new(1, 0, 1, 0) titleText.Text = "Script Source Editor" titleText.TextColor3 = newColor(102, 0, 102)
local scroll = Instance.new("Frame", editor) local barFrame = Instance.new("Frame", scroll) local bar = Instance.new("TextButton", barFrame) local up = Instance.new("TextButton", scroll) local upText = Instance.new("TextLabel", up) local down = Instance.new("TextButton", scroll) local downText = Instance.new("TextLabel", down) scroll.Name = "Scroll" scroll.BackgroundColor3 = newColor(234, 234, 234) scroll.BackgroundTransparency = 0.5 scroll.Position = UDim2.new(1, -21, 0, 20) scroll.Size = UDim2.new(0, 20, 1, -20) barFrame.BackgroundTransparency = 1 barFrame.Position = UDim2.new(0, 0, 0, 20) barFrame.Size = UDim2.new(1, 0, 1, -40) barFrame.Name = "BarFrame" bar.BackgroundColor3 = Color3.new(1, 1, 1) bar.BackgroundTransparency = 0.7 bar.Size = UDim2.new(1, 0, 1, 0) bar.Text = "" bar.Name = "Bar" up.BackgroundColor3 = Color3.new(1, 1, 1) up.BackgroundTransparency = 0.7 up.Size = UDim2.new(0, 20, 0, 20) up.Text = "" up.Name = "Up" upText.FontSize = Enum.FontSize.Size18 upText.Position = UDim2.new(0.5, 0, 0.5, 3) upText.Text = "^" upText.Name = "UpTxt" down.BackgroundColor3 = Color3.new(1, 1, 1) down.BackgroundTransparency = 0.7 down.Position = UDim2.new(0, 0, 1, -20) down.Size = UDim2.new(0, 20, 0, 20) down.Text = "" down.Name = "Down" downText.FontSize = Enum.FontSize.Size14 downText.Position = UDim2.new(0.5, 0, 0.5, 0) downText.Text = "v" downText.Name = "DownTxt"
local source = Instance.new("Frame", editor) local srcHold = Instance.new("Frame", source) local Src_Lines = {} source.Name = "Source" source.BackgroundTransparency = 0.5 source.Position = UDim2.new(0, 20, 0, 20) source.Size = UDim2.new(1, -41, 1, -20) srcHold.BackgroundTransparency = 1 srcHold.Position = UDim2.new(0, 3, 0, 0) srcHold.Size = UDim2.new(1, -3, 1, 0) srcHold.Name = "Holder" for i = 1, 24 do local LINE = Instance.new("TextLabel", srcHold) LINE.BackgroundTransparency = 1 LINE.FontSize = Enum.FontSize.Size10 LINE.Name = "L"..i LINE.Position = UDim2.new(0, 0, 0, i*20-20) LINE.Size = UDim2.new(1, 0, 0, 20) LINE.Text = i==1 and "print 'Hello, world!'" or "" LINE.TextColor3 = Color3.new(0, 0, 0) LINE.TextXAlignment = Enum.TextXAlignment.Left table.insert(Src_Lines, LINE) end
local lines = Instance.new("Frame", editor) local Line_Nums = { } lines.Name = "Lines" lines.BackgroundTransparency = 0.5 lines.Position = UDim2.new(0, 0, 0, 20) lines.Size = UDim2.new(0, 20, 1, -20) for i = 1, 24 do local LINE = Instance.new("TextLabel", lines) LINE.BackgroundTransparency = 1 LINE.FontSize = Enum.FontSize.Size9 LINE.Name = "L"..i LINE.Position = UDim2.new(0, 0, 0, i*20-20) LINE.Size = UDim2.new(1, 0, 0, 20) LINE.Text = i LINE.TextColor3 = Color3.new(0, 0, 0) table.insert(Line_Nums, LINE) end
local lineHighlights = Instance.new("Frame", editor) local Highlights = { } lineHighlights.Name = "LineHighlights" lineHighlights.BackgroundTransparency = 1 lineHighlights.Position = UDim2.new(0, 0, 0, 20) lineHighlights.Size = UDim2.new(1, -1, 1, -20) for i = 1, 24 do local LINE = Instance.new("TextButton", lineHighlights) LINE.BackgroundTransparency = 1 LINE.AutoButtonColor = false LINE.BorderSizePixel = 0 LINE.Name = "L"..i LINE.Position = UDim2.new(0, 0, 0, i*20-20) LINE.Size = UDim2.new(1, -20, 0, 20) LINE.Text = "" LINE.BackgroundColor3 = newColor(255, 255, 102) table.insert(Highlights, LINE) end
local options = Instance.new("Frame", editor) local list = Instance.new("Frame", options) local add = Instance.new("TextButton", list) local edit = Instance.new("TextButton", list) local lremove = Instance.new("TextButton", list) local swap = Instance.new("TextButton", list) local finish = Instance.new("TextButton", list) local title = Instance.new("Frame", options) local titleText = Instance.new("TextLabel", title) options.Name = "Options" options.BackgroundColor3 = Color3.new(0, 0, 0) options.BackgroundTransparency = 0.7 options.BorderSizePixel = 0 options.Position = UDim2.new(0, -151, 0, 0) options.Size = UDim2.new(0, 150, 0, 330) list.Name = "List" list.BackgroundColor3 = newColor(192, 192, 192) list.BackgroundTransparency = 0.7 list.Position = UDim2.new(0, 0, 0, 20) list.Size = UDim2.new(1, -1, 1, -20) add.Name = "Add" add.BackgroundColor3 = newColor(51, 153, 255) add.BackgroundTransparency = 0.7 add.FontSize = Enum.FontSize.Size14 add.Position = UDim2.new(0.1, 0, 0, 10) add.Size = UDim2.new(0.8, 0, 0, 50) add.Text = "Add Line" edit.Name = "Edit" edit.BackgroundColor3 = newColor(51, 153, 255) edit.BackgroundTransparency = 0.7 edit.FontSize = Enum.FontSize.Size14 edit.Position = UDim2.new(0.1, 0, 0, 130) edit.Size = UDim2.new(0.8, 0, 0, 50) edit.Text = "Edit Line" lremove.Name = "Remover" lremove.BackgroundColor3 = newColor(51, 153, 255) lremove.BackgroundTransparency = 0.7 lremove.FontSize = Enum.FontSize.Size14 lremove.Position = UDim2.new(0.1, 0, 0, 70) lremove.Size = UDim2.new(0.8, 0, 0, 50) lremove.Text = "Remove Line" swap.Name = "Swap" swap.BackgroundColor3 = newColor(51, 153, 255) swap.BackgroundTransparency = 0.7 swap.FontSize = Enum.FontSize.Size14 swap.Position = UDim2.new(0.1, 0, 0, 190) swap.Size = UDim2.new(0.8, 0, 0, 50) swap.Text = "Swap Lines" finish.Name = "Finish" finish.BackgroundColor3 = newColor(0, 204, 0) finish.BackgroundTransparency = 0.7 finish.FontSize = Enum.FontSize.Size14 finish.Position = UDim2.new(0.1, 0, 0, 250) finish.Size = UDim2.new(0.8, 0, 0, 50) finish.Text = "Done" title.Name = "Title" title.BackgroundTransparency = 0.7 title.Size = UDim2.new(1, -1, 0, 20) titleText.BackgroundTransparency = 1 titleText.FontSize = Enum.FontSize.Size14 titleText.Size = UDim2.new(1, 0, 1, 0) titleText.Text = "Options" titleText.TextColor3 = newColor(102, 0, 102)
local sType = options:clone() local typedesc = Instance.new("TextLabel", sType.List) sType.Parent = editor sType.Position = UDim2.new(1, 0, 0, 0) sType.Size = UDim2.new(0, 150, 0, 200) sType.List.Edit:remove() sType.List.Finish:remove() sType.List.Swap:remove() sType.List.Add.Name = "LS" sType.List.LS.Text = "LocalScript" sType.List.LS.BackgroundColor3 = newColor(0, 204, 0) sType.List.LS.BorderColor3 = newColor(255, 255, 0) sType.List.LS.Position = UDim2.new(0.1, 0, 0, 60) sType.List.Remover.Name = "NS" sType.List.NS.Text = "Script" sType.List.NS.Position = UDim2.new(0.1, 0, 0, 120) typedesc.Name = "Desc" typedesc.Position = UDim2.new(0.5, 0, 0, 30) typedesc.FontSize = Enum.FontSize.Size12 typedesc.Text = "Type: LocalScript"
local status = Instance.new("Frame", editor) local details = Instance.new("Frame", status) local stat1 = Instance.new("TextLabel", details) local stat2 = Instance.new("TextLabel", details) local title = Instance.new("Frame", status) local titleText = Instance.new("TextLabel", title) status.Name = "Status" status.BackgroundColor3 = Color3.new(0, 0, 0) status.BackgroundTransparency = 0.7 status.BorderSizePixel = 0 status.Position = UDim2.new(0, -151, 0, 330) status.Size = UDim2.new(0, 150, 0, 82) details.BackgroundColor3 = newColor(192, 192, 192) details.BackgroundTransparency = 0.7 details.Position = UDim2.new(0, 0, 0, 20) details.Size = UDim2.new(1, -1, 1, -20) details.Name = "Details" stat1.Name = "Status1" stat1.BackgroundTransparency = 1 stat1.FontSize = Enum.FontSize.Size9 stat1.Position = UDim2.new(0.1, 0, 0, 10) stat1.Size = UDim2.new(0.8, 0, 0, 16) stat1.Text = "Ready" stat1.TextXAlignment = Enum.TextXAlignment.Left stat2.Name = "Status2" stat2.BackgroundTransparency = 1 stat2.FontSize = Enum.FontSize.Size9 stat2.Position = UDim2.new(0.1, 0, 0, 36) stat2.Size = UDim2.new(0.8, 0, 0, 16) stat2.Text = "" stat2.TextXAlignment = Enum.TextXAlignment.Left title.Name = "Title" title.BackgroundTransparency = 0.7 title.Size = UDim2.new(1, -1, 0, 20) titleText.BackgroundTransparency = 1 titleText.FontSize = Enum.FontSize.Size14 titleText.Size = UDim2.new(1, 0, 1, 0) titleText.Text = "Status" titleText.TextColor3 = newColor(0, 128, 0)
local dialog = Instance.new("Frame", g) dialog.BackgroundColor3 = Color3.new(0, 0, 0) dialog.BackgroundTransparency = 0.5 dialog.Name = "Dialog" dialog.Position = UDim2.new(0, 50, 0, 100) dialog.Size = UDim2.new(0, 500, 0, 150) dialog.Active = true dialog.Draggable = true dialog.Visible = false ------ ADD LINE DIALOG ----- local addline = Instance.new("Frame", dialog) local body = Instance.new("Frame", addline) local checkA = Instance.new("TextButton", body) local checkedA = Instance.new("BoolValue", checkA) local checkAF = Instance.new("Frame", checkA) local slash = Instance.new("TextLabel", checkAF) slash.FontSize = Enum.FontSize.Size10 slash.Position = UDim2.new(0, 11, 0, 8) slash.TextColor3 = Color3.new(0, 0, 0) slash.Text = "/" slash.Name = "Slash" slash:clone().Parent = checkAF local veee = Instance.new("TextLabel", checkAF) veee.FontSize = Enum.FontSize.Size10 veee.Position = UDim2.new(0, 9, 0, 11) veee.TextColor3 = Color3.new(0, 0, 0) veee.Text = "v" veee.Name = "V" local checkU = Instance.new("TextButton", body) local checkedU = Instance.new("BoolValue", checkU) local checkUF = Instance.new("Frame", checkU) slash:clone().Parent = checkUF slash:clone().Parent = checkUF veee:clone().Parent = checkUF local codebox = Instance.new("TextBox", body) local ok = Instance.new("TextButton", body) local cancel = Instance.new("TextButton", body) local codelabel = Instance.new("TextLabel", body) local abovelabel = Instance.new("TextLabel", body) local underlabel = Instance.new("TextLabel", body) local title = Instance.new("Frame", addline) local titleText = Instance.new("TextLabel", title) addline.BackgroundTransparency = 1 addline.Name = "AddLine" addline.Size = UDim2.new(1, 0, 1, 0) body.BackgroundTransparency = 1 body.Name = "Body" body.Position = UDim2.new(0, 0, 0, 20) body.Size = UDim2.new(1, 0, 1, -20) cancel.BackgroundColor3 = Color3.new(1, 1, 1) cancel.BackgroundTransparency = 0.5 cancel.FontSize = Enum.FontSize.Size10 cancel.Position = UDim2.new(1, -100, 1, -40) cancel.Size = UDim2.new(0, 75, 0, 30) cancel.Name = "Cancel" cancel.Text = "Cancel" checkA.Name = "CheckboxAbove" checkA.BackgroundColor3 = Color3.new(1, 1, 1) checkA.BackgroundTransparency = 0.2 checkA.Position = UDim2.new(1, -37, 0, 62) checkA.Size = UDim2.new(0, 17, 0, 17) checkA.Text = "" checkedA.Name = "Checked" checkAF.Name = "Check" checkAF.Visible = false checkU.Name = "CheckboxUnder" checkU.BackgroundColor3 = Color3.new(1, 1, 1) checkU.BackgroundTransparency = 0.2 checkU.Position = UDim2.new(0, 175, 0, 62) checkU.Size = UDim2.new(0, 17, 0, 17) checkU.Text = "" checkedU.Name = "Checked" checkUF.Name = "Check" codebox.BackgroundColor3 = Color3.new(1, 1, 1) codebox.BackgroundTransparency = 0.2 codebox.BorderSizePixel = 0 codebox.FontSize = Enum.FontSize.Size11 codebox.Name = "Code" codebox.Position = UDim2.new(0, 110, 0, 20) codebox.Size = UDim2.new(0, 375, 0, 20) codebox.Text = "" codebox.TextColor3 = Color3.new(0, 0, 0) codebox.TextXAlignment = Enum.TextXAlignment.Left ok.BackgroundColor3 = Color3.new(1, 1, 1) ok.BackgroundTransparency = 0.5 ok.FontSize = Enum.FontSize.Size10 ok.Name = "Ok" ok.Position = UDim2.new(1, -185, 1, -40) ok.Size = UDim2.new(0, 75, 0, 30) ok.Text = "Ok" codelabel.BackgroundTransparency = 1 codelabel.FontSize = Enum.FontSize.Size11 codelabel.Name = "Examine" codelabel.Position = UDim2.new(0, 20, 0, 20) codelabel.Size = UDim2.new(0, 75, 0, 20) codelabel.Text = "Code:" codelabel.TextColor3 = Color3.new(1, 1, 1) abovelabel.BackgroundTransparency = 1 abovelabel.FontSize = Enum.FontSize.Size11 abovelabel.Position = UDim2.new(1, -192, 0, 60) abovelabel.Size = UDim2.new(0, 150, 0, 20) abovelabel.Text = "Above selected line" abovelabel.TextColor3 = Color3.new(1, 1, 1) abovelabel.Name = "ALab" underlabel.BackgroundTransparency = 1 underlabel.FontSize = Enum.FontSize.Size11 underlabel.Position = UDim2.new(0, 20, 0, 60) underlabel.Size = UDim2.new(0, 150, 0, 20) underlabel.Text = "Under selected line" underlabel.TextColor3 = Color3.new(1, 1, 1) underlabel.Name = "ULab" title.Name = "Title" title.BackgroundTransparency = 0.7 title.Size = UDim2.new(1, -1, 0, 20) titleText.BackgroundTransparency = 1 titleText.FontSize = Enum.FontSize.Size14 titleText.Size = UDim2.new(1, 0, 1, 0) titleText.Text = "Add Line" titleText.TextColor3 = newColor(0, 0, 0) ----- EDIT LINE DIALOG ----- local editline = addline:clone() editline.Parent = dialog editline.Name = "EditLine" editline.Body.CheckboxAbove:remove() editline.Body.CheckboxUnder:remove() editline.Body.ULab.Name = "PrevLabel" editline.Body.PrevLabel.Text = "Previous Code:" editline.Body.ALab.Name = "PrevCode" editline.Body.PrevCode.TextXAlignment = Enum.TextXAlignment.Left editline.Body.PrevCode.Position = UDim2.new(0, 175, 0, 60) editline.Title.TextLabel.Text = "Edit Line" editline.Visible = false ------- ERROR DIALOG ------- local errorbox = editline:clone() errorbox.Parent = dialog errorbox.Name = "Error" errorbox.Body.Cancel:remove() errorbox.Body.Code:remove() errorbox.Body.PrevLabel:remove() errorbox.Body.PrevCode:remove() errorbox.Body.Examine.FontSize = Enum.FontSize.Size24 errorbox.Body.Examine.Position = UDim2.new(0.5, -38, 0.5, -20) errorbox.Body.Examine.Size = UDim2.new(0, 76, 0, 20) errorbox.Body.Examine.Text = "Please select a line!" errorbox.Visible = false errorbox.Body.Ok.BackgroundTransparency = 0.3 errorbox.Body.Ok.Position = UDim2.new(1, -100, 1, -40) errorbox.Title.TextLabel.Text = "ERROR - Line selection needed!"
addline.Body.CheckboxAbove.MouseButton1Down:connect(function() addline.Body.CheckboxAbove.Checked.Value = true addline.Body.CheckboxAbove.Check.Visible = true addline.Body.CheckboxUnder.Checked.Value = false addline.Body.CheckboxUnder.Check.Visible = false end)
addline.Body.CheckboxUnder.MouseButton1Down:connect(function() addline.Body.CheckboxAbove.Checked.Value = false addline.Body.CheckboxAbove.Check.Visible = false addline.Body.CheckboxUnder.Checked.Value = true addline.Body.CheckboxUnder.Check.Visible = true end)
function createScript() local sc = Instance.new(scriptType) sc.Source = tableconcat(Source_, "\n") local Selected = game:service("Selection"):Get() if #Selected == 0 then sc.Parent = workspace else for _, v in pairs(Selected) do sc:clone().Parent = v end end end
function removeLine() local Sel = selected.Value if Sel > 1 then stat1.Text = "Removing line "..selected.Value table.remove(Source_, selected.Value) numlines.Value = numlines.Value - 1 updateLineNumsAndLines() wait(0.5) stat1.Text = stat1.Text == "Removing line "..Sel and "Ready" or stat1.Text end end
function editLine() local slot = selected.Value Source[slot] = editline.Body.Code.Text updateLineNumsAndLines() hideDialog() clearHighlights() end
function addLine() local slot = addline.Body.CheckboxAbove.Checked.Value and selected.Value > 0 and selected.Value or selected.Value+1 numlines.Value = numlines.Value + 1 table.insert(Source_, slot, addline.Body.Code.Text) addline.Body.Code.Text = "" hideDialog() clearHighlights() updateLineNumsAndLines() end
function hideDialog() dialog.Visible = false clearHighlights() stat1.Text = "Ready" end
function showDialog(Type) if Type == "Add" then addline.Visible = true errorbox.Visible = false editline.Visible = false elseif Type == "Edit" then addline.Visible = false errorbox.Visible = false editline.Visible = true editline.Body.PrevCode.Text = Source[selected.Value] ~= nil and Source[selected.Value] or "" editline.Body.Code:CaptureFocus() else addline.Visible = false errorbox.Visible = true editline.Visible = false end dialog.Visible = true end
function updateScrollbarSizeAndPosition() local num = numlines.Value local ind = index.Value local R = 24/num if R >= 1 then bar.Size = UDim2.new(1, 0, 1, 0) else bar.Size = UDim2.new(1, 0, 24/num, 0) end if R >= 1 then bar.Position = UDim2.new(0, 0, 0, 0) else bar.Position = UDim2.new(0, 0, (ind-1)*(1/num), 0) end end
function updateLineNumsAndLines() local ind = index.Value local num = numlines.Value local _ = 1 for i = ind, ind+23 do Src_Lines[_].Text = Source[i] ~= nil and Source[i] or "" Line_Nums[_].Text = i Line_Nums[_].Visible = Source[i] ~= nil and Source[i] ~= "" _ = _ + 1 end updateScrollbarSizeAndPosition() end
function scrollUp() if index.Value == 1 then return end index.Value = index.Value - 1 updateLineNumsAndLines() end
function scrollDown() print(index.Value, numlines.Value-23) if index.Value == numlines.Value-23 then return end index.Value = index.Value + 1 updateLineNumsAndLines() end
function highlightSelected(highlight) if Line_Nums[tonumber(highlight.Name:match("%d+"))].Visible == false then return end for _, v in pairs(Highlights) do if v==highlight then if v.BackgroundTransparency < 1 then v.BackgroundTransparency = 1 else v.BackgroundTransparency = 0.7 end else v.BackgroundTransparency = 1 end end selected.Value = highlight.BackgroundTransparency < 1 and tonumber(Line_Nums[tonumber(highlight.Name:match("%d+"))].Text) or 0 end
function clearHighlights() for _, v in pairs(Highlights) do v.BackgroundTransparency = 1 end selected.Value = 0 end
up.MouseButton1Down:connect(scrollUp) down.MouseButton1Down:connect(scrollDown) lremove.MouseButton1Down:connect(removeLine) addline.Body.Ok.MouseButton1Down:connect(addLine) addline.Body.Code.FocusLost:connect(function(ent) if ent then addLine() end end) addline.Body.Cancel.MouseButton1Down:connect(hideDialog) editline.Body.Ok.MouseButton1Down:connect(editLine) editline.Body.Code.FocusLost:connect(function(ent) if ent then editLine() end end) editline.Body.Cancel.MouseButton1Down:connect(hideDialog) errorbox.Body.Ok.MouseButton1Down:connect(hideDialog) add.MouseButton1Down:connect(function() if selected.Value ~= 0 then showDialog "Add" stat1.Text = "Adding near line "..selected.Value else showDialog "Error" end end) edit.MouseButton1Down:connect(function() if selected.Value ~= 0 then showDialog "Edit" stat1.Text = "Editing line "..selected.Value else showDialog "Error" end end) swap.MouseButton1Down:connect(function() if S1 then return end if selected.Value == 0 then stat1.Text = "Select first line to swap." selected.Changed:wait() end S1 = selected.Value stat1.Text = "Line "..S1.." selected." stat2.Text = "Select next line to swap." selected.Changed:wait() if selected.Value == 0 then stat1.Text = "SWAP CANCELED!" stat2.Text = "" wait(0.5) stat1.Text = "Ready" S1, S2 = nil, nil return end S2 = selected.Value stat2.Text = "Line "..S2.." selected." wait(0.25) stat1.Text = "SWAPPING..." stat2.Text = "" wait(0.5) stat1.Text = "Ready" Source[S1], Source[S2] = Source[S2], Source[S1] updateLineNumsAndLines() S1, S2 = nil, nil end) finish.MouseButton1Down:connect(function() createScript() Off() end) for _, HL in pairs(Highlights) do HL.MouseButton1Down:connect(function() highlightSelected(HL) end) end sType.List.LS.MouseButton1Down:connect(function() sType.List.LS.BackgroundColor3 = newColor(0, 204, 0) sType.List.LS.BorderColor3 = newColor(255, 255, 0) sType.List.NS.BackgroundColor3 = newColor(51, 153, 255) sType.List.NS.BorderColor3 = newColor(27, 42, 53) scriptType = "LocalScript" sType.List.Desc.Text = "Type: "..scriptType end) sType.List.NS.MouseButton1Down:connect(function() sType.List.NS.BackgroundColor3 = newColor(0, 204, 0) sType.List.NS.BorderColor3 = newColor(255, 255, 0) sType.List.LS.BackgroundColor3 = newColor(51, 153, 255) sType.List.LS.BorderColor3 = newColor(27, 42, 53) scriptType = "Script" sType.List.Desc.Text = "Type: "..scriptType end)
-------------------------- --SUCCESSFUL LOAD MESSAGE- -------------------------- updateLineNumsAndLines() print("Insert LocalScript Plugin Loaded") |
|
|
| Report Abuse |
|
|
sdfgw
|
  |
 |
| Joined: 08 Jan 2009 |
| Total Posts: 41681 |
|
|
| 16 Aug 2011 01:10 PM |
Yeah, I see the use of variable names
but the REPITITION
OGM HUNDREDS OF MONOTONE CODE IT BURNS
I would've used like 1 big nested table, and then a general iteration function to make the lot :u |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2011 01:11 PM |
Wellllll... It helps that I have a place compiler at my disposal. :3 |
|
|
| Report Abuse |
|
|
sdfgw
|
  |
 |
| Joined: 08 Jan 2009 |
| Total Posts: 41681 |
|
|
| 16 Aug 2011 01:23 PM |
oh what
I made one of those in 09 and it caused my PC to crash (not just roblox, the actual computer) so I never did that again
:l
I actually have a serious habit of over-generalising things to avoid unnecessary splitting up of code. e.g. you would probably say
if condition then brick.Color = somecolor3 else brick.Color = someothercolor3 end
I would write
t = {["true"] = somecolor3, ["false"] = someothercolor3} brick.Color = t[tostring(condition)] |
|
|
| Report Abuse |
|
|
|
| |
|
|
| |
|
»
»
|
|
|
|
|