The error occurs because the code cannot initialize the player.
Code: Select all
local player = minetest.localplayer
Reception: We need it to work for CSM Mod.
Code: Select all
local player = minetest.localplayer
Code: Select all
local player = minetest.localplayer
local function dostuff ( something )
...
local pos = player:get_pos()
--error occurs player not defined
Code: Select all
local player = minetest.localplayer
local function dostuff ( something )
...
-- make sure we have a reference to player
if not player and not minetest.localplayer then
return
elseif not player then
player = minetest.localplayer
end
local pos = player:get_pos()
Thank you for the explanation. This information should help get rid of the current problem.zing269 wrote:CSMs load before the player exists in the world so you will need to make sure that you have a reference to the player before you try to use it.
Yes. This code helped to solve the problem with initialization of the player.zing269 wrote: This code will workCode: Select all
local player = minetest.localplayer local function dostuff ( something ) ... -- make sure we have a reference to player if not player and not minetest.localplayer then return elseif not player then player = minetest.localplayer end local pos = player:get_pos()
Users browsing this forum: Bing [Bot] and 2 guests