Wallpaper Engine

Wallpaper Engine

View Stats:
D STIJN Dec 31, 2020 @ 3:24am
Linking multiple parameters to one script/shared variables?
I currently linked a script to one of my parameters, for the sake of this answer let's say it's linked to the scale of an image, making it respond to audio. In case I want to link another parameter to audio as well, I'd have to copy-paste the exact same script in there as well.

Code duplication is something I'd like to avoid, and this also makes the script run twice at the same time (which, for the sake of processing power, is not ideal, especially when automating more than 2 parameters).

Is there a way to create a global variable somewhere in a scene that I can link to a script, and then access that variable from all my other scripts? I feel like this should be possible but I'm just reading over it. Essentially, what I'm trying to do is make 1 script respond to audio, and update a variable, so that the other scripts (linked to parameters) can just read the current value of that variable, and go from there. This avoids having to run the same function 2, 3, 4, or even more times simultaneously.

If this is not currently possible, see this post as a suggestion, because I feel like something like this is quite useful. It both avoids unnecessary code duplication & saves processing power.
< >
Showing 1-4 of 4 comments
Tim  [developer] Dec 31, 2020 @ 4:43am 
There is a global shared object for this purpose, you can assign data to it and access it from different locations. Documentation for this is pretty sparse to non-existant, I will write a new documentation on our new docs website in the near future and incorporate an example there. You sound like you know what you are doing though, so I am sure you'll figure it out. If you have any issues, feel free to ask.

https://wallpaper-engine.fandom.com/wiki/SceneScript_Class_Shared

Last edited by Tim; Dec 31, 2020 @ 6:12am
D STIJN Dec 31, 2020 @ 5:38am 
Yes, that looks exactly like what I was looking for, thanks. I've noticed that the website is still in development so it's understandable that the docs aren't there yet, no pressure. Thanks for the response!
D STIJN Jan 7, 2021 @ 9:56am 
Originally posted by Tim:
I am sure you'll figure it out. If you have any issues, feel free to ask.

Alright it's quite easy to get the hang of, so it only took me a few minutes to figure it out.

One thing I'd like to ask, though, is if there's a good place to attach "general scripts" to? Just code that isn't specific to any parameters in particular. I'd like to use some functions in an update() method that updates the Shared class, but I can't really find a place to put it. Adding the main code into a random parameter that updates Shared feels a bit wrong, even though it works fine.
Biohazard  [developer] Jan 7, 2021 @ 10:03am 
Originally posted by D STIJN:
Alright it's quite easy to get the hang of, so it only took me a few minutes to figure it out.

One thing I'd like to ask, though, is if there's a good place to attach "general scripts" to? Just code that isn't specific to any parameters in particular. I'd like to use some functions in an update() method that updates the Shared class, but I can't really find a place to put it. Adding the main code into a random parameter that updates Shared feels a bit wrong, even though it works fine.

There is no general place on a layer or even in the scene where scripts could be attached to. We are usually adding general scripts to the "visible" property because it's right at the top of the property list and kinda make sense for a general script. You don't have to modify the property and return any values in update/init if you just want to leave the property alone.

We might add options to add general scripts somewhere, but since this doesn't have any technical advantages we don't have a high priority on this right now.
< >
Showing 1-4 of 4 comments
Per page: 1530 50

Date Posted: Dec 31, 2020 @ 3:24am
Posts: 4