Lua脚本中的相对路径失败
所以,这是我们都讨厌的那些太简单而不会失败的错误之一。
我有一个 .lua 文件,除其他外,它尝试通过 Love 的 newImageData 函数加载图像(并将其放入按钮中):
back_button = buttonmanager.createButton("back", love.image.newImageData("../Images/BackButton.png"), width-200, height-105)
Love 加载失败,抛出此错误:
./frame.lua:5: Could not open file ../Images/BackButton.png. Does not exist.
我已经经历了愚蠢的错误过程( “嗯,它真的存在吗?文件夹在哪里?”等等)——文件存在,位于上一级的 Images 文件夹中——我什至可以说“ls ../Images/BackButton.png”从该脚本所在的目录中,它按照我的预期输出 BackButton.png 。
我需要注意一些奇怪的相对路径问题吗?我尝试将其更改为绝对路径,但它给了我同样的错误。
So, here's one of those too-simple-to-fail bugs that we all hate.
I have a .lua file that, among other things, tries to load an image via Love's newImageData function (and place it into a button):
back_button = buttonmanager.createButton("back", love.image.newImageData("../Images/BackButton.png"), width-200, height-105)
Love fails to load, throwing this error:
./frame.lua:5: Could not open file ../Images/BackButton.png. Does not exist.
I've gone through the stupid-mistakes process ("well, does it actually exist? Where is the folder?" etc) -- the file exists, is in the Images folder, which is one level up -- I can even say "ls ../Images/BackButton.png" from the directory this script sits in, and it outputs BackButton.png as I'd expect.
Is there some weird relative pathing issue I need to watch out for? I tried changing it to an absolute path and it gave me the same error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
love.filesystem 模块限制对某些位置的文件的访问:
../Images
目录是否位于游戏文件夹/存档之外?The love.filesystem module restricts access to files in certain locations:
Is the
../Images
directory outside of your game's folder/archive?