We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have a text area on a site where I am dynamically editing p5js code. I want to be able to rerun setup without refreshing the page. does anyone know a way to do this?
One other problem I have is that I only have access to the client side, so php calls to destroy current session will not work. however I can use ajax...
Thanks!
Answers
Move any code from setup() you want rerun into a new function called, say, reset().
Then just call reset() from setup().
And when you want to rerun that code, call reset().
Don't feel bad you didn't think of this on your own - this question comes up a lot!
Thanks for your reply! that's a great idea. Unfortunately it doesn't work for my specific case.
I apologize, I didn't give enough information. I have a code window where users submit sketches and then they press a button to test them.
the test button works by appending the code window in script tags to the end of the doc. So it works fine the first time, but if a user presses test again: the sketch doesn't rerun setup().
I can't use your suggestion because users need to be able to paste sketches directly into the editor.
it's really frustrating. thanks again for the suggestion.
So apparently you can just call setup().
Should have been the first thing I tried.
this is answered.