javascripthtmlprocessing.js

Making processing.js sketch get value from external JS variable


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.

How can I make my Processing.js sketch "see" the variable containing the value of the input field?


Solution

  • You should check out the Processing.js documentation, specifically the JavaScript Quick Start, specifically the Writing Documents that Combine Processing and JavaScript Code section.

    There are three main ways to approach this: you can write Processing code that accesses an external JavaScript variable, or you could write JavaScript code that does something like call a setter function in your Processing code, or you could write JavaScript code directly in your Processing code.

    Any of those approaches would work fine for what you're trying to do. If you still can't get it working, please post a MCVE of what you tried in a new question, and we'll go from there. Good luck.