1

Stack Overflow! I wanted to store variables in another file so that I would load the variables in file 1, and draw the scene in file 2, ex.

closet.js
var message = "Hello there";

drawer.js
draw = function() { text(message, 100, 100); };

So I would do something like that, but instead of importing the files like this;

<canvas data-processing-sources="closet.js drawer.js"></canvas>

I wanted to be able to include them in file 2, sort of like this;

closet.js
var message = "Hello there";

drawer.js
import("closet.js"); draw = function() { text(message, 100, 100); };

Is there a way to do this without including them in the HTML file itself? Thanks in advance :)

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
tufda
  • 27
  • 6
  • Possible duplicate of [Include a JavaScript file in another JavaScript file?](http://stackoverflow.com/questions/950087/include-a-javascript-file-in-another-javascript-file) – Kevin Workman Nov 24 '15 at 13:24

1 Answers1

0

Check out this question, which yours might even be a duplicate of. It lists several ways to do this in JavaScript, including using JQuery or dynamically adding the <script> tags to the <head> of your page.

But if you're using the Processing editor, you have another option: use classes by creating a new tab in the Processing editor. For all your purposes, you can treat this as a separate file. So lets say you created a separate Closet tab with a message variable. Your main sketch code might look like this:

Closet c = new Closet();
draw = function() {
  text(c.message, 100, 100);
};

I think this is probably the way to go. It seems like you're trying to over-engineer a solution: either include the files in the html (this is what 99% of all JavaScript code does) or use a class (this is what 99% of all Processing code does).

Community
  • 1
  • 1
Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
  • 1
    Oki, thanks again Kevin. You really must be a busy man! I see you everywhere on this site :)! Thanks for helping out the entire StackOverflow community :) – tufda Nov 25 '15 at 08:13