Does where an end goes matter?

Sometimes I realize I need an if statement or something in my scripts in its a pain indenting that code so does where I indent my end matter?

3 Likes

Functionally, no. It definitely helps when trying to read functions, but it is not a requirement of the lua language.

Try to indent functions and such though.

3 Likes

No, its isnt required, but it is extremely good practice to indent as it makes it better for you and others who wanna review your script easier.

2 Likes

Essentially: Your friends will want to not be friends with you if you make your code unreadable.

2 Likes

Exactly. It just helps you in the better run. For me, it is very stressful to have unorganized coding. It just doesn’t give me motivation to continue on.

1 Like

If you select the lines of code you want to indent then you can simply press tab once and they’ll all indent for you. Likewise, if you do shift + tab it’ll shift the indentation of the code to the left.

1 Like

Not really, but make sure it’s there.

Like @CoolGuyBoiBruh said, it’s extremely good practice to properly indent your code, as it can look messy and confusing the more code you have, especially while using else or elseif within if statements. For example…

Messy code/no indenting:

local function printText(string1)
print(string1)
end

if #game.Players:GetPlayers() == 10 then
printText("Max players have been reached in server")
elseif #game.Players:GetPlayers() ~= 10 then
printText("Space left for players to join")
end

Neat code/indenting:

local function printText(string1)
    print(string1)
end

if #game.Players:GetPlayers() == 10 then
    printText("Max players have been reached in server")
elseif #game.Players:GetPlayers() ~= 10 then
    printText("Space left for players to join")
end

You can see the difference. And if it’s annoying for you to indent, I’m positive that there’s an auto-indent option in the settings menu.

1 Like

@DecodedMint You are absolutely correct. Scripters at first knowledge or starting scripting at least, should know to indent regardless. It really helps in the long run. Great response.

Ends do matter @dVenomHD @CoolGuyBoiBruh, don’t say they don’t. It tells the code when it ends, and in which line the scope ends, for example:

if true then
    if false then
        print("foo")
    end
end

Is different than:

if true then
end
    if false then
        print("foo")
end

(improper indentation to show what I mean)


But it’s not a requirement?

We weren’t saying whether they should exist, we were saying if they needed to be indented. Please read the posts.

An example of what we mean:

for _,v in pairs(TableOfThings) do print(v.Name) end

is virtually the same as

for _,v in pairs(TableOfThings) do
    print(v.Name)
end

The indentation and locations are different, but they functionally do the exact same thing

It is not an argument of whether you need a closing statement (you do), but if it needs to be formatted in a certain way

Yeah. If you wish to reply to a post @VegetationBush please read what has been said before replying.

Which one looks better?
Indents

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
function ConsiderAllow(Consider) {
    return __awaiter(this, void 0, void 0, function () {
        return __generator(this, function (_a) {
            return [2 /*return*/, new Promise(function () {
                    return typeof Consider;
                })];
        });
    });
}

No indents:

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
function ConsiderAllow(Consider) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, new Promise(function () {
return typeof Consider;
})];
});
});
}

minified

"use strict";var __awaiter=this&&this.__awaiter||function(t,n,e,r){return new(e||(e=Promise))(function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function u(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e(function(t){t(n)})).then(a,u)}c((r=r.apply(t,n||[])).next())})},__generator=this&&this.__generator||function(t,n){var e,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;a;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=n.call(t,a)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}};function ConsiderAllow(t){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(n){return[2,new Promise(function(){return typeof t})]})})}

Obfuscated:

var _0x2073=['trys','value','return','iterator','throw','then','next','apply','function','__generator','ops','done','pop','call','label','length'];(function(_0x4b8498,_0x207355){var _0x56f630=function(_0x18cfb0){while(--_0x18cfb0){_0x4b8498['push'](_0x4b8498['shift']());}};_0x56f630(++_0x207355);}(_0x2073,0x1a1));var _0x56f6=function(_0x4b8498,_0x207355){_0x4b8498=_0x4b8498-0x0;var _0x56f630=_0x2073[_0x4b8498];return _0x56f630;};'use strict';var __awaiter=this&&this['__awaiter']||function(_0x2589d0,_0x516b29,_0x34b807,_0x173f68){return new(_0x34b807||(_0x34b807=Promise))(function(_0x13ec13,_0x509c45){function _0x372e2d(_0x134456){try{_0x39841e(_0x173f68[_0x56f6('0x5')](_0x134456));}catch(_0x5a2466){_0x509c45(_0x5a2466);}}function _0x6f2cb3(_0x1e7eba){try{_0x39841e(_0x173f68['throw'](_0x1e7eba));}catch(_0x1144d6){_0x509c45(_0x1144d6);}}function _0x39841e(_0x5202c0){var _0x11ca13;_0x5202c0[_0x56f6('0xa')]?_0x13ec13(_0x5202c0[_0x56f6('0x0')]):(_0x11ca13=_0x5202c0[_0x56f6('0x0')],_0x11ca13 instanceof _0x34b807?_0x11ca13:new _0x34b807(function(_0x40493e){_0x40493e(_0x11ca13);}))[_0x56f6('0x4')](_0x372e2d,_0x6f2cb3);}_0x39841e((_0x173f68=_0x173f68[_0x56f6('0x6')](_0x2589d0,_0x516b29||[]))[_0x56f6('0x5')]());});},__generator=this&&this[_0x56f6('0x8')]||function(_0x25078f,_0x2bddc2){var _0x909728,_0x5d08b5,_0x232fde,_0x3d514f,_0x38a4d4={'label':0x0,'sent':function(){if(0x1&_0x232fde[0x0])throw _0x232fde[0x1];return _0x232fde[0x1];},'trys':[],'ops':[]};return _0x3d514f={'next':_0x82236f(0x0),'throw':_0x82236f(0x1),'return':_0x82236f(0x2)},_0x56f6('0x7')==typeof Symbol&&(_0x3d514f[Symbol[_0x56f6('0x2')]]=function(){return this;}),_0x3d514f;function _0x82236f(_0xbb76f){return function(_0x1bde57){return function(_0x4f38ae){if(_0x909728)throw new TypeError('Generator\x20is\x20already\x20executing.');for(;_0x38a4d4;)try{if(_0x909728=0x1,_0x5d08b5&&(_0x232fde=0x2&_0x4f38ae[0x0]?_0x5d08b5[_0x56f6('0x1')]:_0x4f38ae[0x0]?_0x5d08b5[_0x56f6('0x3')]||((_0x232fde=_0x5d08b5[_0x56f6('0x1')])&&_0x232fde[_0x56f6('0xc')](_0x5d08b5),0x0):_0x5d08b5[_0x56f6('0x5')])&&!(_0x232fde=_0x232fde['call'](_0x5d08b5,_0x4f38ae[0x1]))[_0x56f6('0xa')])return _0x232fde;switch(_0x5d08b5=0x0,_0x232fde&&(_0x4f38ae=[0x2&_0x4f38ae[0x0],_0x232fde[_0x56f6('0x0')]]),_0x4f38ae[0x0]){case 0x0:case 0x1:_0x232fde=_0x4f38ae;break;case 0x4:return _0x38a4d4[_0x56f6('0xd')]++,{'value':_0x4f38ae[0x1],'done':!0x1};case 0x5:_0x38a4d4[_0x56f6('0xd')]++,_0x5d08b5=_0x4f38ae[0x1],_0x4f38ae=[0x0];continue;case 0x7:_0x4f38ae=_0x38a4d4[_0x56f6('0x9')][_0x56f6('0xb')](),_0x38a4d4[_0x56f6('0xf')][_0x56f6('0xb')]();continue;default:if(!(_0x232fde=(_0x232fde=_0x38a4d4['trys'])[_0x56f6('0xe')]>0x0&&_0x232fde[_0x232fde[_0x56f6('0xe')]-0x1])&&(0x6===_0x4f38ae[0x0]||0x2===_0x4f38ae[0x0])){_0x38a4d4=0x0;continue;}if(0x3===_0x4f38ae[0x0]&&(!_0x232fde||_0x4f38ae[0x1]>_0x232fde[0x0]&&_0x4f38ae[0x1]<_0x232fde[0x3])){_0x38a4d4[_0x56f6('0xd')]=_0x4f38ae[0x1];break;}if(0x6===_0x4f38ae[0x0]&&_0x38a4d4[_0x56f6('0xd')]<_0x232fde[0x1]){_0x38a4d4[_0x56f6('0xd')]=_0x232fde[0x1],_0x232fde=_0x4f38ae;break;}if(_0x232fde&&_0x38a4d4[_0x56f6('0xd')]<_0x232fde[0x2]){_0x38a4d4[_0x56f6('0xd')]=_0x232fde[0x2],_0x38a4d4[_0x56f6('0x9')]['push'](_0x4f38ae);break;}_0x232fde[0x2]&&_0x38a4d4[_0x56f6('0x9')][_0x56f6('0xb')](),_0x38a4d4['trys']['pop']();continue;}_0x4f38ae=_0x2bddc2[_0x56f6('0xc')](_0x25078f,_0x38a4d4);}catch(_0x4fd33e){_0x4f38ae=[0x6,_0x4fd33e],_0x5d08b5=0x0;}finally{_0x909728=_0x232fde=0x0;}if(0x5&_0x4f38ae[0x0])throw _0x4f38ae[0x1];return{'value':_0x4f38ae[0x0]?_0x4f38ae[0x1]:void 0x0,'done':!0x0};}([_0xbb76f,_0x1bde57]);};}};function ConsiderAllow(_0x39be75){return __awaiter(this,void 0x0,void 0x0,function(){return __generator(this,function(_0x385e15){return[0x2,new Promise(function(){return typeof _0x39be75;})];});});}

For a prettier view it matters, but as a compiler view, nah doesn’t make a difference

The indentation is much better for the eyes, but please consider OP asked whether it matters to indent code or not, so please don’t go too off topic.

1 Like

Jeez… I wish not to encounter that. Getting to the point, idents are better.

Not off topic, cuz I said my point at the end, so don’t say that I went off-topic when you didn’t read it fully

My bad mate. Anyways, @vSabov, has this satisfied your question? Or perhaps do you need more of an explanation for this topic?

I dont think he is much of an active user. I could be wrong.

In my opinion, where the end goes matters, it takes a little more time, yes but it also makes it much easier to fix problems found in your script. Such as the fact the console points out exactly what line your script had an error it would be much harder to find as it is normally at most a few lines of code.