Making processing.js sketch get value from external JS variable

时间:2017-04-06 17:10:02

标签: javascript html processing.js

I have a game written in Javascript with the Processing.js library. I want to make highscores for that game, and for that I want the user to be able to type a name in an input tag in the page HTML. The problem is that I don't know how to make my Processing.js sketch "see" the variable containing the value of the input field. Does anyone know how I can do this? Thanks in advanced

1 个答案:

答案 0 :(得分:1)

您应该查看Processing.js文档,特别是JavaScript Quick Start,特别是Writing Documents that Combine Processing and JavaScript Code部分。

有三种主要方法可以解决这个问题:您可以编写访问外部JavaScript变量的处理代码,或者您可以编写JavaScript代码来执行类似于在处理代码中调用setter函数的代码,或者您可以直接编写JavaScript代码在您的处理代码中。

任何这些方法都可以正常运行。如果您仍然无法使其正常运行,请在新问题中发布MCVE您尝试过的内容,我们将从那里开始。祝你好运。