Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

is this script right?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
2+2=4
if (2 + 2 == 4) then
print("2+2=4. This is correct")
else
print("2+2 is not 4 it is 9. Check your math")
end

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

Yes, except remember that the first line is not valid Lua.

If it's simply a remark about the code (like it is) then it should be in a comment, specified with two hyphens:

-- 2 + 2 = 4

As a stylistic note, the parenthesis around 2 + 2 == 4 are not required and would usually be omitted.

In addition, it is best practice to tab code to make the "blocks" (the things which are part of if, while, for, function, etc) more obvious:

-- 2+2=4
if 2 + 2 == 4 then
    print("2+2=4. This is correct")
else
    print("2+2 is not 4 it is 9. Check your math")
end

0
the parentheses around "2+2=4. This is correct" would also be omitted. 1waffle1 2908 — 10y
0
While they can be, I don't see it very commonly and don't consider it good practice since that can only be done with literal strings and tables. BlueTaslem 18071 — 10y
Ad

Answer this question