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 » Scripters
Home Search
 

Tidy

Previous Thread :: Next Thread 
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
25 Mar 2015 03:26 PM
Is this the most efficient, tidiest way to write this code? If not, what is?

local chosenPos = Vector3.new(-68.6, 2, -15.9)
local chosenPos1 = Vector3.new(-68.8, 2, 18.7)
local spawn = Vector3.new(38.3, 0.1, 2.2)


function startBuild()

local themes = {"House", "Garden", "Boat"}
local Players = game.Players:GetPlayers()
local rTheme = table.remove(themes, math.random(#themes))
local fChose = table.remove(Players, math.random(#Players))
local sChose = table.remove(Players, math.random(#Players))
game.Workspace.p1.Value = fChose.Name
game.Workspace.p2.Value = sChose.Name
local builders = Instance.new("Message", game.Workspace)
builders.Text = "The builders this round are "..fChose.Name.." and "..sChose.Name
wait(4)
builders.Text = "The chosen theme is "..rTheme
wait(4)
builders:Destroy()
fChose.Character.HumanoidRootPart.CFrame = CFrame.new(chosenPos)
sChose.Character.HumanoidRootPart.CFrame = CFrame.new(chosenPos1)
wait(5)

for i, player in pairs(game.Players:GetChildren()) do
if player.Character and player.Character:FindFirstChild("Torso") then
player.Character.Torso.CFrame = CFrame.new(spawn + Vector3.new(0, i * 5, 0))
end
end
wait(2)
end

while true do
wait(2)
if #game.Players:GetPlayers() > 2 then
print("Games Starting")
wait(2)
startBuild()
else
print("More Players Needed")
end
end
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
25 Mar 2015 03:29 PM
a way of writing tidy code for the most part is a matter of opinion
Report Abuse
distalDigitPhalanx is not online. distalDigitPhalanx
Joined: 25 Jan 2015
Total Posts: 1509
25 Mar 2015 03:30 PM
I make a big deal of having my code being tidy and readable. As a result of that, I generally end up with long variable names, and 2/3 of my lines being comments or whitespace. I prefer it that way, but someone would probably swear that it's way too much. Or too litte, I guess.

If you can read your code, it's "good enough"
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
25 Mar 2015 03:32 PM
OK, scrap tidy. Is this the most efficient way?
Report Abuse
distalDigitPhalanx is not online. distalDigitPhalanx
Joined: 25 Jan 2015
Total Posts: 1509
25 Mar 2015 03:33 PM
No. But you don't want that either way. Not for this. It's not like your calling anything 100 times a second, so efficiency is not important for what you're making.
But I guess you're asking out of interest, not because it's practical.
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
25 Mar 2015 03:34 PM
Well, i have OCD and i hate it not to be perfect, is that the shortest, cleanest way i could write the script?
Report Abuse
LucasLua is not online. LucasLua
Joined: 18 Jun 2008
Total Posts: 7386
25 Mar 2015 03:35 PM
So long as all your naming conventions have a clear purpose behing their names and the process of each function is easy to understand, your code is considered tidy. Since those rules can be subjective at times people often disagree on what is considered "tidy" code.

Also, your Vector3 values aren't going to be exact the way you declared them (floating point inaccuracies are a plague on the computer science industry). However, I'm going to assume that those positions don't have to be accurate down to the Nth decimal point, lol.
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
25 Mar 2015 03:37 PM
there are loads of different ways to write a script, so yeah you probably could make it shorter

or longer

or whatever size you want

as long as you and other people can understand your code, and it is efficient, then that's good code i'd say
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
25 Mar 2015 03:37 PM
Thank you,, i was jsut checking there wern't any ways for me to merge two lines in to one
Report Abuse
distalDigitPhalanx is not online. distalDigitPhalanx
Joined: 25 Jan 2015
Total Posts: 1509
25 Mar 2015 03:40 PM
You can do it on one line :P

function startBuild() local themes = {"House", "Garden", "Boat"} local Players = game.Players:GetPlayers() local rTheme = table.remove(themes, math.random(#themes)) local fChose = table.remove(Players, math.random(#Players)) local sChose = table.remove(Players, math.random(#Players)) game.Workspace.p1.Value = fChose.Name game.Workspace.p2.Value = sChose.Name local builders = Instance.new("Message", game.Workspace) builders.Text = "The builders this round are "..fChose.Name.." and "..sChose.Name wait(4) builders.Text = "The chosen theme is "..rTheme wait(4) builders:Destroy() fChose.Character.HumanoidRootPart.CFrame = CFrame.new(chosenPos) sChose.Character.HumanoidRootPart.CFrame = CFrame.new(chosenPos1) wait(5) for i, player in pairs(game.Players:GetChildren()) do if player.Character and player.Character:FindFirstChild("Torso") then player.Character.Torso.CFrame = CFrame.new(spawn + Vector3.new(0, i * 5, 0)) end end wait(2) end while true do wait(2) if #game.Players:GetPlayers() > 2 then print("Games Starting") wait(2) startBuild() else print("More Players Needed") end end
Report Abuse
LucasLua is not online. LucasLua
Joined: 18 Jun 2008
Total Posts: 7386
25 Mar 2015 03:41 PM
While you could theoretically cut down on similar lines by making a few helper functions, in this case it really isn't necessary as you don't have very many similar lines.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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