Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question about Lua variables #3509

Open
Zbizu opened this issue Jul 27, 2021 · 4 comments
Open

question about Lua variables #3509

Zbizu opened this issue Jul 27, 2021 · 4 comments
Labels
enhancement Increase or improvement in quality, value, or extent question Questions that needs answering but do not require code changes

Comments

@Zbizu
Copy link
Contributor

Zbizu commented Jul 27, 2021

I loaded tfs folder to vs code and the editor shits itself with warnings because second value in this kind of declaration is nil:

local a, b = 10

print(a, b) -- 10   nil

examples of occurences:

local result, bless = "Received blessings:"

local instrument, chance = instruments[item:getId()]

local random, tmpItem = math.random(0, 10000) * 0.01

should this be corrected?

@Zbizu Zbizu changed the title question about variables question about Lua variables Jul 27, 2021
@nekiro
Copy link
Member

nekiro commented Jul 27, 2021

IMO no

@marmichalski
Copy link
Contributor

It does not make any sense in check_bless, it could be simplified in music, clay_lump seems the only one that makes sense 🤔

@Zbizu
Copy link
Contributor Author

Zbizu commented Jul 28, 2021

I'd personally go for more clear declaration such as:

-- one declaration, one value
local instrument = instruments[item:getId()]
-- clear declaration of local variable with no value assigned (nil)
local chance

the code is more readable for someone who isn't familiar with lua and time to execute differences are so small they don't matter if any exist

another supporting argument is that I don't see variables being declared this way uint32_t x, y = 15, 20 in source files either unless they're in a vector or a pair and have matching types

May be a bit unrelated, but this was Mark's opinion on a very short dice.lua I've wrote back in 2014:
#362 (comment)

and the file he commented on:
https://github.com/otland/forgottenserver/blob/8d931632b57c8376ccc5cbc8a32c67ac34cb50d1/data/actions/scripts/other/dice.lua

@EPuncker EPuncker mentioned this issue Jul 29, 2021
3 tasks
@EPuncker
Copy link
Contributor

yes I agree, feel free to create a PR for the music one thought

@EPuncker EPuncker added enhancement Increase or improvement in quality, value, or extent question Questions that needs answering but do not require code changes labels Jul 29, 2021
@EPuncker EPuncker mentioned this issue Oct 25, 2021
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Increase or improvement in quality, value, or extent question Questions that needs answering but do not require code changes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants