1
Archive: Player.lua, my module
local Player = {}
local function funcPlayer()
local player = {}
local self = {name="", points = 0}
local setPoints = function(newPoints)
self.points = newPoints
end
local getPoints = function ()
return self.points
end
local setName = function(newName)
self.name = newName
end
local getName = function()
return self.name
end
local f__tostring = function()
return "(" .. self.name .. ", " .. self.points .. ")"
end
setmetatable(player, {
__tostring = f__tostring
})
player.getPoints = getPoints
player.setPoints = setPoints
player.getName = getName
player.setName = setName
return player
end
Player = funcPlayer()
return Player
File that requests the module: Players.lua
local tabPlyer = require("Player")
Error message:
[Running] lua "c:\Users\tct9\Documents\Lua\ScriptLua\Games\Players.lua"
lua: c:\Users\tct9\Documents\Lua\ScriptLua\Games\Players.lua:1: module 'Player' not found:
no field package.preload['Player']
no file 'c:\Users\tct9\Documents\Lua\lua\Player.lua'
no file 'c:\Users\tct9\Documents\Lua\lua\Player\init.lua'
no file 'c:\Users\tct9\Documents\Lua\Player.lua'
no file 'c:\Users\tct9\Documents\Lua\Player\init.lua'
no file '.\Player.lua'
no file 'c:\Users\tct9\Documents\Lua\Player.dll'
no file 'c:\Users\tct9\Documents\Lua\loadall.dll'
no file '.\Player.dll'
no file 'c:\Users\tct9\Documents\Lua\Player52.dll'
no file '.\Player52.dll'
stack traceback:
[C]: in function 'require'
c:\Users\tct9\Documents\Lua\ScriptLua\Games\Players.lua:1: in main chunk
[C]: in ?
What to do to use this module?
I am using Vscode.
Variable PATH: ...; C: Users tct9 Documents Lua
Variable LUA_PATH: C: Users tct9 Documents Lua
Moon Path: C: Users tct9 Documents Lua
Script Path: C: Users tct9 Documents Lua Scriptlua Games
Where is the module Player.lua? See in the error message where Lua searched the module.
– lhf
In:"C: Users tct9 Documents Lua Scriptlua Games". I already changed the place file, for example "C: Users tct9 Documents Lua", but the error remains the same.
– Lucius Matos