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
|
  |
| Joined: 15 May 2011 |
| Total Posts: 18684 |
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
| |
|
| |
|
|
| 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 |
|
|
|
| 19 Mar 2012 02:41 PM |
| Oh I thought he meant my post, which was C#. |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 19 Mar 2012 02:55 PM |
| semicolon after everey ban |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
| |
|
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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|