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

vines/init.lua:46: attempt to index local 'player' (a nil value) #11

Closed
Bastrabun opened this issue Dec 21, 2021 · 7 comments
Closed

vines/init.lua:46: attempt to index local 'player' (a nil value) #11

Bastrabun opened this issue Dec 21, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@Bastrabun
Copy link

This falling lua calls a dig event with no player.

2021-12-21 19:07:33: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'builtin' in callback luaentity_Step(): .../mtlive1/.minetest/mods/plantlife_modpack/vines/init.lua:46: attempt to index local 'player' (a nil value)
2021-12-21 19:07:33: ERROR[Main]: stack traceback:
2021-12-21 19:07:33: ERROR[Main]: .../mtlive1/.minetest/mods/plantlife_modpack/vines/init.lua:46: in function 'on_dig'
2021-12-21 19:07:33: ERROR[Main]: ...ive1/5.4.1/Minetest_live/bin/../builtin/game/falling.lua:270: in function 'try_place'
2021-12-21 19:07:33: ERROR[Main]: ...ive1/5.4.1/Minetest_live/bin/../builtin/game/falling.lua:380: in function 'func'
2021-12-21 19:07:33: ERROR[Main]: ...inetest_live/bin/../builtin/profiler/instrumentation.lua:106: in function <...inetest_live/bin/../builtin/profiler/instrumentation.lua:100>

This is like 380 of falling.lua:

-- Try to actually place ourselves
                if not failure then
                        failure = not self:try_place(bcp, bcn) <--- 380
                end

And here's line 270 of falling.lua:

-- it's drops
                if n2.name ~= "air" and (not nd or nd.liquidtype == "none") then
                        if nd and nd.buildable_to == false then
                                nd.on_dig(np, n2, nil) <--- line 270
                                -- If it's still there, it might be protected
                                if core.get_node(np).name == n2.name then
                                        return false
                                end
                        else
                                core.remove_node(np)
                        end
                end

For my reference 1198

@wsor4035
Copy link
Contributor

in theory this is as simple as changing https://github.com/mt-mods/plantlife_modpack/blob/master/vines/init.lua#L46 to wielded_item = player and player:get_wielded_item() (basically check for player, else leave the variable nil). will test later

@wsor4035
Copy link
Contributor

pinging @JordanL2 as blame reveals it was there PR that broke it

@JordanL2
Copy link
Contributor

Apologies for that miss, @wsor4035 your solution sounds good to me.

@BuckarooBanzay BuckarooBanzay added the bug Something isn't working label Dec 25, 2021
@wsor4035
Copy link
Contributor

@JordanL2 it appears there is a lot of globals in vines/init.lua is that intended?

@JordanL2
Copy link
Contributor

Probably not, I'll be able to check myself soon but it's very likely I forgot the local keyword for some variables. Probably all the settings at the top?

@wsor4035
Copy link
Contributor

yeah, vscode (with luacheck extension) was lighting up like a Christmas tree

@JordanL2
Copy link
Contributor

JordanL2 commented Dec 27, 2021

@wsor4035 I raised this PR to fix the missing local keywords:
#13

Also did another small fix at the same time. Can you check there aren't any unnecessary global variables afterwards? I think there should just be vines declared globally. (EDIT: I've installed luacheck and checked it, no errors or warnings)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants