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
 

Good scripting Habits

Previous Thread :: Next Thread 
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
19 Mar 2012 02:16 PM
What do you consider good scripting habits? (For readability) What I can think of (that I do):

► Tab code
► Sometimes put ; at the end of lines
► Use 0.1, not .1
► Separate everything into functions.
► Define everything at the top of the script that is global.
► Tab out the equal signs so their all equal.

My scripts look like this. The top of the script has a define area, and the top of each function has a define area. Then it has an area to define more functions, and then finally, I execute them all. Each function is like that. I always use local variables, so all variables of a scope can be found at the top of the scope. I also do tables in a tabbed sort of way.

My if statements also look like this:

    if part and part.Name and part.Name == "Hello" and not part.Anchored then

I tend to use 'not' instead of ~=.

--------------
-- DEFINE --
--------------

local variable = 3534
local variable = 3534
local variable = 3534
local variable = 3534
local vari       = 3534 -- All Equal signs tabbed

-------------------
-- FUNCTIONS --
-------------------

function FindParts(Parts)
    local x    = "Hello"
    local yno = "Man

    local function Loop(Hello)
        print(game.Workspace:GetChildren()[1])
    end

    Loop("Hello")
    print("Hello there")
end

-----------------
-- EXECUTE --
-----------------

FindParts(game.Workspace:GetChildren()))
wait(3)
FindParts(game.Workspace.Model:GetChildren())


There are several things I would like to work on doing:
► Using game:GetService() (Started doing this recently)
► Learn how to use Metatables
► Always define local functions.
Report Abuse
Tenal is not online. Tenal
Joined: 15 May 2011
Total Posts: 18684
19 Mar 2012 02:20 PM
[ Content Deleted ]
Report Abuse
bozothekiller01 is not online. bozothekiller01
Joined: 09 Mar 2011
Total Posts: 222
19 Mar 2012 02:21 PM
^ how do you do it?

im exactly the same way. ic ant stand anythng like "x=1" it has to be "x = 1;".
Report Abuse
trappingnoobs is not online. trappingnoobs
Joined: 05 Oct 2008
Total Posts: 19100
19 Mar 2012 02:23 PM
checking if Part.Name is a bad habit, since if it's not actually got a name property some-thing's gone horribly wrong, so there _should_ be an error.
Report Abuse
bozothekiller01 is not online. bozothekiller01
Joined: 09 Mar 2011
Total Posts: 222
19 Mar 2012 02:24 PM
but isnt part.name null?
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
19 Mar 2012 02:25 PM
I was just randomly typing. Of course I wouldn't check for part.Name. :D
Report Abuse
ggfunny1234 is not online. ggfunny1234
Joined: 09 Jul 2010
Total Posts: 3432
19 Mar 2012 02:26 PM
@trapping

That's exactly what I was thinking. You would only need to check if the part is in existence, and if its name is == "Hello".
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
19 Mar 2012 02:28 PM
IT WAS JUST A RANDOM IF STATEMENT!!!!!

Anyway, what are your habits like? What does your code look like?
Report Abuse
bozothekiller01 is not online. bozothekiller01
Joined: 09 Mar 2011
Total Posts: 222
19 Mar 2012 02:33 PM
i typed this out 3 seconds ago...

#define KEY(vk) GetASyncKeyState

#include [iostream]
#include [cstdlib]
#include [ctime]

using namespace std;

int main()
{
srand(time((0)));
int num = rand();
int number = (num % 100);

while(1) {
cout << number;
break;
}
}
Report Abuse
trappingnoobs is not online. trappingnoobs
Joined: 05 Oct 2008
Total Posts: 19100
19 Mar 2012 02:34 PM
roblox probably removed tabs, but:

public bool collision(Vector2 screenPosition, Vector2 size)
{
mapSection mapCollisionPossibilities = toMapMinMax(screenPosition, size);

for (int y = (int)mapCollisionPossibilities.topLeft.Y; y <= mapCollisionPossibilities.bottomRight.Y; y++)
{
for (int x = (int)mapCollisionPossibilities.topLeft.X; x <= mapCollisionPossibilities.bottomRight.X; x++)
{
if (x >= 0 && y >= 0 && y < tiles.Count && x < tiles[y].Count)
{
if (tileManager.tileTypes[tiles[y][x]].collideable == true)
{
return true;
}
}
}
}

return false;
}
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
19 Mar 2012 02:34 PM
Not takling about C++ here. We're talking about Lua, which is scripting.
Report Abuse
trappingnoobs is not online. trappingnoobs
Joined: 05 Oct 2008
Total Posts: 19100
19 Mar 2012 02:36 PM
it's C# not C++

you can tell because it's better

and my habits are cross-language, like most sane people's what I do in language Y I usually do in language X; that applies to spacing before and after signs, etc.
Report Abuse
bozothekiller01 is not online. bozothekiller01
Joined: 09 Mar 2011
Total Posts: 222
19 Mar 2012 02:37 PM
That's C++ not C#...
Report Abuse
trappingnoobs is not online. trappingnoobs
Joined: 05 Oct 2008
Total Posts: 19100
19 Mar 2012 02:38 PM
No it's C# idiot.
Report Abuse
bozothekiller01 is not online. bozothekiller01
Joined: 09 Mar 2011
Total Posts: 222
19 Mar 2012 02:40 PM
Are you trying to troll or something? My post is C++ not C#. They are completely different, I don't even know how someone could ever confuse them.
Report Abuse
trappingnoobs is not online. trappingnoobs
Joined: 05 Oct 2008
Total Posts: 19100
19 Mar 2012 02:41 PM
Oh I thought he meant my post, which was C#.
Report Abuse
bozothekiller01 is not online. bozothekiller01
Joined: 09 Mar 2011
Total Posts: 222
19 Mar 2012 02:45 PM
UGH! Im an idiot i should hav eknwon you were talking about yours from the start
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
19 Mar 2012 02:55 PM
> Back on topic

So what other habits do you have?
Report Abuse
bozothekiller01 is not online. bozothekiller01
Joined: 09 Mar 2011
Total Posts: 222
19 Mar 2012 02:55 PM
semicolon after everey ban
Report Abuse
ggfunny1234 is not online. ggfunny1234
Joined: 09 Jul 2010
Total Posts: 3432
19 Mar 2012 03:00 PM
- I try to tab my code out (sometimes if I'm in a hurry, I don't bother)

- Add comments to the code if I'm planning on giving it to someone else

- My mind's kinda blank right now, so I can't think of everything that I usually do
Report Abuse
enumeration is not online. enumeration
Joined: 17 Dec 2011
Total Posts: 2552
19 Mar 2012 03:07 PM
[ Content Deleted ]
Report Abuse
RA2lover is not online. RA2lover
Joined: 09 Nov 2008
Total Posts: 1254
19 Mar 2012 03:08 PM
i think i'll have an habit to use LinkedSource to update scripts without updating the place...
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
19 Mar 2012 03:09 PM
Is it better to use

0.2

or .2?

Also, how do you link sources?
Report Abuse
Ozzypig is not online. Ozzypig
Joined: 27 Mar 2008
Total Posts: 4906
19 Mar 2012 03:10 PM
>► Use 0.1, not .1

^ Why? There's no semantic reason to keep the period.
Report Abuse
1Ra is not online. 1Ra
Joined: 02 May 2010
Total Posts: 2400
19 Mar 2012 03:11 PM
I use the same style, Unless there are a ton of functions, then i place the functions at the bottom to act like a library.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 2Go to page: [1], 2 Next
 
 
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