简体   繁体   English

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

[英]Have a paper js file that can be imported as a module

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.一个是用于游戏玩法的普通 javascript 文件,另一个是用于所有图形的 paperscript 文件。 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.我想从主文件的 paperscript 文件中调用函数,但据我所知,它需要加载type="module"才能调用函数,但它也需要加载type="text/paperscript"使其作为 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.如果有另一种从不同文件调用函数的方法,我想听听,或者是否有办法在同一个脚本元素中同时包含type="module"type="text/paperscript"

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如果这不可能,我知道我可以使用 javascript 而不是 paperscript 但我宁愿不使用因为我看到的所有示例都使用 paperscript

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.我学习了 python 并且是 javascript 的新手并且没有意识到你可以从其他文件调用函数,在 python 中你只能通过使用模块来做到这一点。

Here I can declare a variable as window.<myVariableName> in paperscript to be able to access it from raw javascript.在这里,我可以在 paperscript 中将变量声明为window.<myVariableName>以便能够从原始 javascript 访问它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM