Xpressionist: do Xp-scripted channel value changes persist beyond the frame they are calculated in? |
|
|
| Posted: 04 August 2007 07:44 AM |
[ Ignore ]
|
|
|
Member
Total Posts: 79
Joined 2007-04-18
|
I have this Xpressionist script to turn a Light into an intermitent one, changing Intensity every 27 frames
if (frame % 27 == 0) //(if I put a single “equal” sign it’ll give me an error message. Why?)
{
if (NavLight_Mstr.Intensity=0)
NavLight_Mstr.Intensity=1;
else
NavLight_Mstr.Intensity=0;
}
The initial Intensity was 1, as set in the Light Info window.
Seeing that it doesn’t work, it dawned on me that Xpressionist-driven value changes might not survive the frame they are being calculated for. Is that so? What would be the best way of doing things that flipflop between two values in time? Playing with the Sin () function plus some value constrainer?
Revising the manual, I think I’ve found out that there is no way to set global-like variables that persist from frame to frame. That ought to be an important addition to EI 7.x
|
|
|
|
|
|
| Posted: 04 August 2007 01:08 PM |
[ Ignore ]
[ # 1 ]
|
|
|
Newbie
Total Posts: 28
Joined 2007-03-07
|
Like you said. XPressionist only calculates on the frame itself. It just fills in the values on a per-frame basis. Here’s a little script that should do the trick.
The first two lines should be pretty straightforward.
The third line is the one that does the job. I’m not a programmer, so for all I know, there’s a much more elegant solution out there, but it works.
The variable “onoff” constantly switches from 0 to 1. At the moment, the script just drops that values into “Light_1.GlowIntensity” but you can easily replace that last line with a “if (onoff == 0)… else...” type of statement.
double blinkspeed = 27; // speed of blinking
double offset = 0; // frame offset for when blinking starts
double onoff = fmod (trunc (((frame+offset) / blinkspeed) +2) , 2);
Light_1.GlowIntensity = onoff;
|
|
|
|
|
|
| Posted: 04 August 2007 01:15 PM |
[ Ignore ]
[ # 2 ]
|
|
|
Sr. Member
Total Posts: 309
Joined 2007-03-11
|
Hi, Juanxer
We never scripted on XP, but it has “C” lang syntax, so let us answer. First off, don’t be confused, every programmer does same/similar errors There are a few things just “need to remember”:
1) “=” is an assignment. If you wrote “if (NavLight_Mstr.Intensity=0) “ it means: assign 0(zero) to NavLight_Mstr.Intensity. The “if” analyses the returned value, in your case it’s always 0. Thus the first branch of “if” will be never executed - instead “NavLight_Mstr.Intensity=0;” will be performed always. Note: some C compilers in this case generate a warning “possible unwanted assignment”
2) “==” is a comparison. So, the correct vers (at leasr in “C") should be:
if ((frame % 27) == 0) {
if (NavLight_Mstr.Intensity == 0)
NavLight_Mstr.Intensity = 1;
else
NavLight_Mstr.Intensity = 0;
}
Good luck
|
|
|
|
|
|
| Posted: 04 August 2007 01:21 PM |
[ Ignore ]
[ # 3 ]
|
|
|
Newbie
Total Posts: 12
Joined 2007-03-14
|
hmmm....
First, the easy… if you use a single “=” sign, you are not declaring an if statement, but a value. The double equal sign is a standard use in an if statement.
second, the moderate one… instead of using “if (NavLight_Mstr.Intensity=0)” try using if (NavLight_Mstr.Intensity(frame - 1)=0)” this tells XP to get the last value, you do not want the current value, as you are planning on changing it.
Third, you have a couple of options here… the one to use depends on you.
I would not use the “if (frame % 27 == 0)” method, and I dont think XP supports this format. Use:
divisor = 27;
remainder = fmod( frame , divisor );
if (remainder == 0) {
}
next, you should try using XP keyframe mode, so it doesnt just give you a flash, and sets a keyframe each change. There are other methods if this doesnt meet what you need, but it should be a start.
Cj
Juanxer - 04 August 2007 07:44 AM I have this Xpressionist script to turn a Light into an intermitent one, changing Intensity every 27 frames
if (frame % 27 == 0) //(if I put a single “equal” sign it’ll give me an error message. Why?)
{
if (NavLight_Mstr.Intensity=0)
NavLight_Mstr.Intensity=1;
else
NavLight_Mstr.Intensity=0;
}
The initial Intensity was 1, as set in the Light Info window.
Seeing that it doesn’t work, it dawned on me that Xpressionist-driven value changes might not survive the frame they are being calculated for. Is that so? What would be the best way of doing things that flipflop between two values in time? Playing with the Sin () function plus some value constrainer?
Revising the manual, I think I’ve found out that there is no way to set global-like variables that persist from frame to frame. That ought to be an important addition to EI 7.x
|
|
|
|
|
|
| Posted: 04 August 2007 02:48 PM |
[ Ignore ]
[ # 4 ]
|
|
|
Member
Total Posts: 79
Joined 2007-04-18
|
Thank you for your answers. I’ll study them all and see what approach suits me better. As the last time I did any programming was some decades ago, in Pick BASIC (please don’t laugh at me :D), I didn’t give enough importance to the “=” vs. “==” issue, even if I suspected I should have done so.
I hope some consideration has been given to having variables whose value can survive from frame to frame in a new version of the plugin, anyway. That would be superuseful.
(Actually, an expression such as
if ( frame % 24 > 0)
NavLight_StrbMaster.Intensity=0;
else
NavLight_StrbMaster.Intensity=1;
etc.
for a one frame-long strobe style of navigational light works quite well, actually. We ought to get to know if that’s a fluke or a legal use of the Xp language)
|
|
|
|
|
|
| Posted: 04 August 2007 04:26 PM |
[ Ignore ]
[ # 5 ]
|
|
|
Member
Total Posts: 57
Joined 2007-04-14
|
The script
if ( intensity==0 )
{
// if 0, change it to 1
intensity = 1;
}
else
{
// if 1, change it to 0
intensity = 0;
}
Will depend on the number of times you execute it on a frame. So execute it once, all 1->0, all 0->1. The execute it again: all 0->1, all 1->0.
--
Same thinking error like in
intensity++;
which will increase intensity, BUT depending on how many times you press “update project” :(
--
You want frame 0-26: 0, frame 27-53: 1, frame 54-…
r = (frame & 54 ); // r=0......53 will give you a full cycle of 54 frames
// map that to intensity = 0,0,0...0, 1,1,1,1....1 :
onoff = floor(r/27); // will give you “0” for r=0..26, will give you “1” for r=27..53
Patrick
|
|
|
|
|
|
| Posted: 04 August 2007 08:03 PM |
[ Ignore ]
[ # 6 ]
|
|
|
Member
Total Posts: 79
Joined 2007-04-18
|
A related question: I am using the Console command to check the results of the calculations in each of your solutions and some new of mine. What does getting a “nan” instead of a numerical result mean?
|
|
|
|
|
|
| Posted: 04 August 2007 08:18 PM |
[ Ignore ]
[ # 7 ]
|
|
|
Newbie
Total Posts: 12
Joined 2007-03-14
|
NAN = Not A Number…
Make sure to initialize all variables before calling, and amke sure what you are calling is a number.
Cj
Juanxer - 04 August 2007 08:03 PM A related question: I am using the Console command to check the results of the calculations in each of your solutions and some new of mine. What does getting a “nan” instead of a numerical result mean?
|
|
|
|
|
|
| Posted: 04 August 2007 09:13 PM |
[ Ignore ]
[ # 8 ]
|
|
|
Member
Total Posts: 79
Joined 2007-04-18
|
Mmm. My problem is here: up to using this formula I get a value between 0 and nearly 2 for the “navlight” variable.
double navlight = 2 * ( fmod (frame,(27*2)) / (27*2) )
|
|
|
|
|
|
| Posted: 04 August 2007 09:28 PM |
[ Ignore ]
[ # 9 ]
|
|
|
Member
Total Posts: 79
Joined 2007-04-18
|
If I retouch it by adding the “floor” constrainer function, it ought to give me just two kinds of values: 0 and 1. I get the dreaded “nan”, instead.:
double navlight = floor( 2 * ( fmod (frame,(27*2)) / (27*2) ) )
|
|
|
|
|
|
| Posted: 04 August 2007 09:29 PM |
[ Ignore ]
[ # 10 ]
|
|
|
Member
Total Posts: 79
Joined 2007-04-18
|
(I am not putting the “;” at the end of lines right now because this forum system is eating half my messages’ text once I put some Xp code inside)
|
|
|
|
|
|
| Posted: 04 August 2007 09:47 PM |
[ Ignore ]
[ # 11 ]
|
|
|
Newbie
Total Posts: 12
Joined 2007-03-14
|
Do you have the actual code you want to use…
basically your formula as written is:
navlight = floor (2 = (fmod (frame, 1) ) );
giving 2
I find it better to debug a formula if you pull out pieces. Then you can debug a piece and verify it is giving what you want. Then if needed you can create one line.
my_value = fmod (frame, 1)
mod_value = 2 * my_value;
my_result = floor (mod_value);
navlight = my_result;
Cj
Juanxer - 04 August 2007 09:28 PM If I retouch it by adding the “floor” constrainer function, it ought to give me just two kinds of values: 0 and 1. I get the dreaded “nan”, instead.:
double navlight = floor( 2 * ( fmod (frame,(27*2)) / (27*2) ) )
|
|
|
|
|
|
| Posted: 05 August 2007 05:22 AM |
[ Ignore ]
[ # 12 ]
|
|
|
Member
Total Posts: 77
Joined 2007-03-08
|
Personally I’d use a method more like…
-----
double Blend = 5
NavLight_Mstr.Intensity = clamp (0,1,Blend*sin(frame*(20/3)));
-----
This will do…
clamp (1,0 - Keep the values between 1 and 0.
Blend* - choose how jerkily the light changes intensity… The higher the number, the more jerky.
And for some reason, if you switch the positions of the 0 and the 1 in the clamp statement, it makes the switch instant… Like what you had before.
sin(frame* - will change the intensity using a sine wave, based on the frame no.
(20/3))); - will make it so that the no of frames the whole loop takes is 54… So one switch every 27 frames, like you wanted… That is, 360(degrees)/54(no of frames you want the loop to take)
Hope this works
|
|
|
|
|
|
| Posted: 05 August 2007 06:26 AM |
[ Ignore ]
[ # 13 ]
|
|
|
Member
Total Posts: 77
Joined 2007-03-08
|
Or if you NEED something more like what you have there, try something like…
if (Xpressionist.to27[frame-1] != 27)
{
Flicker.Intensity = Flicker.Intensity[frame-1];
Xpressionist.to27 = Xpressionist.to27[frame-1]+1;
}
else
{
Xpressionist.to27 = 1;
if (Flicker.Intensity[frame-1] !=0)
Flicker.Intensity=0;
else
Flicker.Intensity=1;
}
|
|
|
|
|
|
| Posted: 05 August 2007 07:24 AM |
[ Ignore ]
[ # 14 ]
|
|
|
Sr. Member
Total Posts: 309
Joined 2007-03-11
|
BJMonkey - 05 August 2007 06:26 AM
Flicker.Intensity = Flicker.Intensity[frame-1];
Xpressionist.to27 = Xpressionist.to27[frame-1]+1;
A dangerous/unstable code. It’s better to avoid such “travellings in time”
|
|
|
|
|
|
| Posted: 05 August 2007 07:27 AM |
[ Ignore ]
[ # 15 ]
|
|
|
Member
Total Posts: 77
Joined 2007-03-08
|
Why?
If it’s set to update all frames, surely it should work fine?
Isn’t that what simulations do?
And this is such a simple simulation, I doubt that he’ll encounter too many problems.
|
|
|
|
|