Refreshing Javascript effectively
Hi, I'm starting to learn the JS system for Max. I'm going through the tutorials, trying out some ideas of my own, and I'm seeing some quirky behavior. Here is the scenario: I will have mis-typed a variable name. This results in an error message in the Max monitor window, "misspelledVariabel is not defined". Spot the mistake, fix my typo (misspelledVariabel to misspelledVariable) and save. Still says the same error, even though the object that is being talked about isn't there (referencing misspelledVariabel, even though that isn't in the js script any longer). I save my Max patch, same issue. I use the 'compile' message on the JS object. Same issue.
No amount of saving the js file, compiling the js file, and saving the patch (or any shuffling of that routine) seems to fix it. Only when I save everything, completely shutdown Max and then restart it does the message go away.
I am using Max's built in text editor inside of Max 7.
This definitely puts the breaks on my coding flow. Anyone know what I might be doing wrong?
Reloading/compiling JS usually works fine in Max. Maybe you have several instances of [js] (probably in abtractions) or several views of one abstraction with your JS code open?
I think that might have been the case. I wound up closing up shop for the day and when I restarted my computer and started working again I didn't seem to have the same problems. Thanks for your help.
If there are any extra resources outside of existing C74 tutorials on Javascript inside of Max/MSP, I would love to read up on any suggestions that people might have.
Do you have "autowatch" turned on? In the global part of your JS code (i.e., at the top of your script) type the line
autowatch = 1;
This will cause the js object to reload the script when it detects that the script has been changed and saved.
Regarding your question about additional learning resources, see:https://cycling74.com/forums/good-exercices-on-js-in-maxmsp/
Hi Dominic,
Same problem here in 2022 with Max 8.3. See my post here :
https://cycling74.com/forums/js-autowatch-issue-when-used-with-js-require
See answer from Jeremy who is working at C'74 : 'autowatch = 1' is still not working as expected when using require(), it's a limitation of Max.
I've found a temporary solution which works for me : simply double click on the name of your main js file (the one you put in a Max patcher), select for example the last two 'js' letters of the file extension, then retype 'js' + [Enter]. Now your JS file should be reloaded correctly, without the need to save your Max project, close Max, relaunch Max and reopen your project... ;)
Regards,
Guillaume