I’m programming a psychological experiment using labjs and I want to add p5 functionalities to some of the screens. My understanding is that in order for things not to break, I need to use p5’s instance mode to make sure that my canvas is created within the right component.
My question is: how do I save variables to the experiment global environment from within the “sketch” function I define?
Thanks GoToLoop! That’s very helpful. For some reason I can’t get it to work this way but this may well have more to do with the specific interaction with labjs. E.g. I’m not sure that the argument that I’m providing to parent is indeed an html element or the right html element, and I’m not sure how to check that.
The problem is that the in Labjs I’m not directly creating the html file, I’m writing a json file instead that is then interpreted by the library core to create an html file. So it’s not clear what is the component’s id. I tried to inspect the resulting html file and I think the component has no id?
But potentially there’s an even more profound problem: I included an alert within the setup function but I’m not seeing any alert coming up. I imagine that I should?
Okay so this is weird, because in the instance mode version things worked, so I imagine setup() got called. But when using it in global mode it’s not even called. What would prevent it from being called in global mode?
I mean, I don’t understand what you mean by “Under normal circumstances it doesn’t matter whether the p5js lib is run before or after a global mode sketch.”
What exactly can be run before or after the sketch? Do you mean the < src > line in which I load the library?
This all thing is kind of hidden from me with the labjs interface. with labjs I control when scripts are executed with labjs’ own tailored tags, which I assume are then translated to generic ones. I inspected the resulting html file and I have “defer=“True””, which as far as I understand means that the script is run when the page is loaded.
So this is definitely working outside labjs, but I couldn’t get it to work inside it. Must be something about the very specific details of details of how labjs is implemented.
Again, many thanks!