有一个可以作为模块导入的纸JS文件

发布于 2025-01-22 14:49:28 字数 298 浏览 4 评论 0原文

我正在制作游戏,我想将我的代码分为两个文件。一个是游戏玩法的普通JavaScript文件,另一个用于所有图形的论文文件。我想从主文件从paperscript文件调用函数,但据我所知,它需要加载type =“ module”让我能够调用函数,但是它还需要加载type =“ text/paperscript”才能用作论文。 如果有一个请求的方法可以从其他文件调用函数,我想听到有关它的信息PaperScript“ 在同一脚本元素中。

如果不可能,我知道我可以使用JavaScript而不是Paperscript

I am making a game and I would like to have my code split into two files. One, an ordinary javascript file for the gameplay, the other a paperscript file for all the graphics. I want to call functions from the paperscript file from the main file, but as far as I can see it needs to be loaded with type="module" for me to be able to call functions, but it also needs to be loaded with type="text/paperscript" for it to work as paperscript.
If there is annother way to call functions from a different file I would like to hear about it, or if there is a way to include both type="module" and type="text/paperscript" in the same script element.

If this is not possible I know I could use javascript not paperscript but I would rather not because all the examples I have seen are using paperscript

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

肤浅与狂妄 2025-01-29 14:49:28

我已经弄清楚了如何做我想做的事,现在我感到非常愚蠢。我学到了Python,并且是JavaScript的新手,并且没有意识到您只能从其他文件中调用函数,在Python中,您只能使用模块来执行此操作。

在这里,我可以将一个变量声明为窗口。

I've figured out how to do what I want and I feel very stupid now. I learned python and am new to javascript and didn't realise that you could just call functions from other files, in python you can only do this by using modules.

Here I can declare a variable as window.<myVariableName> in paperscript to be able to access it from raw javascript.

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