PDA

View Full Version : Scripted Render Effects & Variables


RErender
04-28-2009, 03:56 PM
I keep getting errors when I try to search the forum so I'm not sure if this has been covered.

I have written a scripted render effect, everything was working great while I was editing but I found that the global variables that i was passing it were only working after the script had been evaluated, when the render effect is in it's plugin state it ignores the globals. Any way to work around this?

Thanks

Bobo
04-28-2009, 04:22 PM
I keep getting errors when I try to search the forum so I'm not sure if this has been covered.

I have written a scripted render effect, everything was working great while I was editing but I found that the global variables that i was passing it were only working after the script had been evaluated, when the render effect is in it's plugin state it ignores the globals. Any way to work around this?

Thanks

What are these globals used for and where are you passing the data from?
Or better, WHY do you have to use global variables in the effect?

Any additional information about what you are doing and why would be useful. Normally, it is not typical to use global variables in a render effect since it is a plugin and can handle all its data locally unless you have to communicate with other scripts. In that case, both scripts would have to pre-declare these variables as global to ensure that they would be visible in the global scope regardless of which script was evaluated first at startup.

RErender
04-28-2009, 05:00 PM
Hi Bobo, thanks for the help, I am actually using Maxscriber as my reference and method for typing to the frame buffer. :)

The idea for the script is to stamp the frame with info that is read in from a database and stored in a global for network rendering, so yes I am passing data from script to script. I had thought that I would need to declare the global in both places but I was concerned the array would be reset by the render effect each time it ran and that seems to be the case. With the global being declared ( global theDate = #() ) in the "on apply" section it just clears the array at render. I hope I am just being dense but I cannot find a way to make it work.

RErender
04-28-2009, 05:28 PM
Ok got it :)

Needed to educate myself on "predefining" variables.

Thanks for your help

RErender
04-28-2009, 05:30 PM
hmm, keeps putting my post on top of yours, heh, anyways that was the ticket, thanks

Bobo
04-28-2009, 05:31 PM
There is a difference between "declaration" and "definition".

global theData -- this is a declaration. creates undefined value, but the variable will exist
global theData = #() --this is a definition. It overwrites the value

You can also do conditional definition to prevent undefined values inside the code:

global theData
if theData == undefined do theData = #()

The first line will declare the variable. If it did not exist so far, it will be created and initialized to undefined. Then the second line will check if that is the case and initialize it to an empty array only if it was a new declaration. If it was already defined by another script, it won't be touched.

You can do this in both scripts to ensure the global exists and that is has a valid (but empty) initial value. Once the source script sets the array to real data, the other script will only ensure the variable is declared but won't overwrite the data.

CGTalk Moderation
04-28-2009, 05:31 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.