Lua脚本中的相对路径失败

发布于 2024-10-02 12:19:26 字数 579 浏览 0 评论 0原文

所以,这是我们都讨厌的那些太简单而不会失败的错误之一。

我有一个 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乱了心跳 2024-10-09 12:19:26

love.filesystem 模块限制对某些位置的文件的访问:

此模块提供对两个位置的文件的访问,并且仅在两个位置:

* .love 文件的根文件夹。 (或者目录)。
* 写入目录的根文件夹。

../Images 目录是否位于游戏文件夹/存档之外?

The love.filesystem module restricts access to files in certain locations:

This module provides access to Files in two places, and two places only:

* The root folder of the .love-file. (Alternatively a directory).
* The root folder of the write directory.

Is the ../Images directory outside of your game's folder/archive?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文