0

I declared a global variable in lua in VS code starting with a lowercase character.

score = 0

Then I encountered an issue that a global variable should not begin with a lowercase character although it did not result in any sort of error. The code worked perfectly fine but I was constantly displayed this issue for each global variable that I declared in lowercase initial.

the issue that was displayed

This lead to a few question: "Should I begin my global variables with an uppercase letter? Will it make my code more easy to inspect and understand? Is this issue only for Lua or other languages too?". I would like to know your opinions and suggestions. Thanks y'all for the help in advance.

4
  • 6
    It's a warning from your IDE, not lua. In general, it doesn't matter how you choose variable naming as long as it is consistent across the entire code. Making it upper case helps you differentiating between local and global. You should prefer local. You can disable the warning in your IDE.
    – Luke100000
    Jun 22, 2022 at 5:46
  • Should I use Score or SCORE for this global? Any suggestions?
    – user16999379
    Jun 22, 2022 at 5:51
  • all upper case are usually constants, so I personally would recommend Score
    – Luke100000
    Jun 22, 2022 at 5:55
  • 2
    I also found this: lua-users.org/wiki/LuaStyleGuide, you can see how vague they are too
    – Luke100000
    Jun 22, 2022 at 5:55

1 Answer 1

0

The Lua language server extension provides diagnostics which can be individually disabled via Visual Code Manage Settings (Ctrl+,):

  1. Lua.diagnostics.disable
  2. Select a diagnostic to disable. In this case lowercase-global

or globally:

  1. Lua.diagnostics.enable

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy