PDA

View Full Version : Lcript troubles



Djamu
07-08-2004, 10:43 AM
Why is this not working ?

@version 2.2
@warnings
@script channel

objName = "relative";
Sumtotal = 0;
Result = 0;

create: channel
{
setdesc("distance tracker");
}
destroy
{
}
process: ca, frame, time
{
obj = Mesh(objName);
chan = obj.firstChannel();
Result = chan.value(time);
Sumtotal = Sumtotal + Result;
ca.set(Sumtotal);
}

even if Result = 0 Sumtotal increases, sometimes (???? )
if result <> 0 then addition is also wrong ( 5 times result=1 Sumtotal <> 5
ca.set(Sumtotal) goes to first channel, that's fine for now

So I tried this ( i'll show the processes only the other parts stay the same )
thought this would zero Sumtotal on frame=0 yes it does, but it does it for every frame so Sumtotal is always == Result

process: ca, frame, time
{
if ( frame == 0 )
Sumtotal = 0;
obj = Mesh(objName);
chan = obj.firstChannel();
Result = chan.value(time);
// Sumtotal = ca.get(time);
Sumtotal = Sumtotal + Result;
ca.set(Sumtotal);
}

Tried this

process: ca, frame, time
{
obj = Mesh(objName);
chan = obj.firstChannel();
Result = chan.value(time);
Sumtotal = ca.get(time);
Sumtotal = Sumtotal + Result;
ca.set(Sumtotal);
}


Doen't work neither Sumtotal == Result, so got the idea to use arrays

so I tried this

process: ca, frame, time
{
if ( frame == 0 )
Sumtotal[frame+1] = 0;

obj = Mesh(objName);
chan = obj.firstChannel();
Result = chan.value(time);

Sumtotal[frame+2] = Sumtotal[frame+1] + Result;
ca.set(Sumtotal[frame+2]);
}

then I'm getting the error illegal index value [0] provided

Hu ? on frame 0 frame ==0 so frame+1 should be 1 on frame 0 no ?


Help !!!! it seems that the frame variable value can be different from the timeline frame counter
any other method to get the frame number ?

Karmacop
07-08-2004, 11:01 AM
Umm ... can I just ask what you're trying to do ... I haven't made a channel script but you're really doing something wrong ....

Djamu
07-08-2004, 11:10 AM
that was quick !!!

well basically I'm trying to accumulate the result of an expression
this result goes to the X-axis of a Null called relative

objName = "relative";

obj = Mesh(objName);
chan = obj.firstChannel();
// getting the value of x-axis of relative
Result = chan.value(time);

this works fine

but this doesn't

Sumtotal = Sumtotal + Result;

tried any variation I could imagine but .....
:confused:

Karmacop
07-08-2004, 11:11 AM
Ok, I think I realised what you were trying to do, so tell me if this works

@version 2.2
@warnings
@script channel

objName = "relative";
Sumtotal = 0;
Result = 0;

create: channel
{
setdesc("distance tracker");

}
destroy
{
}
process: ca, frame, time
{
obj = Mesh(objName);
chan = obj.firstChannel();
Result = chan.value(time);
Sumtotal = chan.value(time) + chan.value(time - 1);
ca.set(Sumtotal);
}

What you were doing wrong (which I should have explained better :p) was that each time lightwave "ran" this script Sumtotal was getting larger and larger. You can see this by adding the script, and then resizing the graph editor window.

What I THINK you wanted to do was to add the previous frame's value with the current frame's value. So what I've done is mad the script "work" ... but I'm not sure if it's working how you want it to ie, frame 3's value would be frame 0 + frame 1 + frame 2's value.

Karmacop
07-08-2004, 11:16 AM
If only I replied a minute faster :p

Djamu
07-08-2004, 11:23 AM
nope it's not working

and yes

but I'm not sure if it's working how you want it to ie, frame 3's value would be frame 0 + frame 1 + frame 2's value.

this is exactly how how want it, so that for example the value @ frame 100 == ( frame 1 + frame 2 + ........ )

Karmacop
07-08-2004, 11:23 AM
Just another note: time is second not frames ... I don't know how I missed that ... so change it from 1, otherwise what you're doign is very delayed :p . I changed it to 0.01 to get it fairly accurate. Oh .. and it seems to work how you want it to :)

Djamu
07-08-2004, 11:24 AM
hey look you just made your 800 th post ;)

Djamu
07-08-2004, 11:27 AM
will change time to frame, but on some previous tests I noticed that the frame value insn't neccesarely the same as the time line frame number or am I wrong ?

Karmacop
07-08-2004, 11:32 AM
Woo 800 .. and in a forum I hardly post in :p

No don't change it to frame, time it probably more accurate ... or more portable anyway ...

Umm .. I guess make a loop ...

.. and I'm not sure about the timeline frame thing ..

Karmacop
07-08-2004, 11:40 AM
Hmm, I just realised what you're trying to do is find the integral of the curve .... but I'm not really sure how you'd do that maybe use simpson's rule ... of course I'm not sure how you'd change that around to work for you ...

I'm off to bed so good luck, but if you haven't figured this out in 24 hours or so I'll continue to try and help.

Djamu
07-08-2004, 11:42 AM
na doesn't work neither
the closest I got was not to reread the Sumtotal


like this

process: ca, frame, time
{
obj = Mesh(objName);
chan = obj.firstChannel();
Result = chan.value(time);
Sumtotal = Sumtotal + Result;
ca.set(Sumtotal);
}


but as soon as I do this or want to reset that value ( on frame 0 ) it goes wrong, so I guess this shouldn't work at all - bug ? -

process: ca, frame, time
{
if (frame == 0) <<<<<<<<<
Sumtotal = 0; <<<<<<<<<

obj = Mesh(objName);
chan = obj.firstChannel();
Result = chan.value(time);
Sumtotal = ca.get(time); <<<<<<<<<
Sumtotal = Sumtotal + Result;
ca.set(Sumtotal);
}

Djamu
07-08-2004, 11:47 AM
I don't know if you realise that this is going to be used as a distance tracker, the channel I get the result from has this expression

vmag( <[motion.Position.X,Frame+1],[motion.Position.Y,Frame+1],[motion.Position.Z,Frame+1]> - <[motion.Position.X],[motion.Position.Y],[motion.Position.Z]> )

this expression calculates the travelled distance per frame
that result goes to the Lscript and .....

should accumulate the total distance travelled ( if it's working ):mad:

Djamu
07-08-2004, 11:53 AM
I just realised what you're trying to do is find the integral of the curve


Exactly !!

faulknermano
07-13-2004, 02:34 PM
i dont know if this helps, but channel filter, like motion scripts refer to frame or time NOT on runtime (if i used the term correctly). channel filters 'pre-determine' values before displaying them (e.g. in the graph editor).

i think you have to find a way to get your curve internally. if not, then you might want to create a separate 'non-callback' func to pre-fetch your values and cache them internally. but i think, if memory of my experience serves, calling them at 'run-time' will not work.

Karmacop
07-13-2004, 07:48 PM
I'm not sure if it helps. What I've been trying is to is to call a loop like this

distance: chan, time
{
dist = chan.value(0);
step = 0.001;
for (i = 0; i <= time; i += step) {
dist += (chan.value(i) - chan.value(i - step) / 2);
}
dist = (dist * step);
return(dist);
}

It doesn't work though ... it's very weird. I think a better way to do it would be to work with each keyframe .. but I'm not sure.

faulknermano
07-13-2004, 08:51 PM
Originally posted by Karmacop
I'm not sure if it helps. What I've been trying is to is to call a loop like this

distance: chan, time
{
dist = chan.value(0);
step = 0.001;
for (i = 0; i <= time; i += step) {
dist += (chan.value(i) - chan.value(i - step) / 2);
}
dist = (dist * step);
return(dist);
}

It doesn't work though ... it's very weird. I think a better way to do it would be to work with each keyframe .. but I'm not sure.


the argument time in the your distance func is not necessarily what you expect.

try someting like



distance: chan, startTime, endTime
{
dist = chan.value(0);
step = 0.001;
for (i = startTime; i <= endTime; i += step) {
dist += (chan.value(i) - chan.value(i - step) / 2);
}
dist = (dist * step);
return(dist);
}



... where startTIme and endTime are manually inputted into the argument.. not that this is not a callback and should be used probably with the event mechanism of the channel filter (which i never got to use all this time). or maybe you can call this func upon user request.

Karmacop
07-13-2004, 10:17 PM
Where is it getting time from then? Isn't time the current time that it's testing for? But yeah, I'm probably doing something vert wrong, I don't understand these motion lscripts :p

faulknermano
07-14-2004, 12:24 AM
Originally posted by Karmacop
Where is it getting time from then? Isn't time the current time that it's testing for? But yeah, I'm probably doing something vert wrong, I don't understand these motion lscripts :p

yes, at first they were hard to understand. the thing to remember is that they are 'pre-determined.' to answer your question directly, the time it is testing for does not necessarily mean the current time YOU are on. for example, in motion scripts, it calls your script to figure out the motion path. that means it calls the lscript as many times as it needs to draw the motion path. the time is being fed to your script, but not the current time only. rather the whole range that lightwave needs to do what it has to do.

i think it is the same with channel filter scripts.

Djamu
07-18-2004, 12:23 PM
Thx for the replies guys

I've sended this a week ago to a newtek engineer who replied on a thread in another forum. I think it's bug related, as my 1st solution should work.

I'm not sure yet because I didn't get any reply yet :rolleyes:

It's kind of weird, because in my experience with programming ( non Lscript ) accumulation of results is a function used very often.

Therefore it's very strange that it seems not possible in Lscript and that nobody ever needed it.

mmmmm this can't be :(

Karmacop
07-21-2004, 08:59 AM
I don't think it's a bug, I just think that Lightwave works in a way that doesn't seem straight foward to us.

Djamu
07-21-2004, 09:14 AM
Originally posted by Karmacop
I don't think it's a bug, I just think that Lightwave works in a way that doesn't seem straight foward to us.

must be, as even the Newtek engineers can't figure it out,
( for now ) ;)

faulknermano
07-21-2004, 09:29 AM
Originally posted by Djamu


It's kind of weird, because in my experience with programming ( non Lscript ) accumulation of results is a function used very often.

Therefore it's very strange that it seems not possible in Lscript and that nobody ever needed it.

mmmmm this can't be :(

hi djamu,

it is possible to get accumulation, but you just cant do it at runtime because you cant predict when lscript is going to call your process func.

i must admit, however, that it was super confusing at first. bob hood had to explain it to everyone in the lscript mailing list too. ;)

Djamu
07-21-2004, 09:53 AM
Originally posted by faulknermano
hi djamu,

it is possible to get accumulation, but you just cant do it at runtime because you cant predict when lscript is going to call your process func.

i must admit, however, that it was super confusing at first. bob hood had to explain it to everyone in the lscript mailing list too. ;)

............

any advice on where I can find this ? ( the mailing list, topic ... )
a hint on how I could precalculate it using matrices ?
:confused:

faulknermano
07-21-2004, 09:56 AM
Originally posted by Djamu
............

any advice on where I can find this ? ( the mailing list, topic ... )

:confused:

if you're looking for the actual code, you can refer to the posts i made above explaining it. as far bob hood's explanation, i would probably have to look it up first and see if i can find it. you can also subscribe to lscript mailing list. look at newtek's site (or the sdk docs). there's a link there.

Djamu
07-21-2004, 10:02 AM
K thanks..

one more thing, ( might sound stupid ), why is there an Lscript mailing list if they have a forum around here ??????

faulknermano
07-21-2004, 10:05 AM
Originally posted by Djamu
K thanks..

one more thing, ( might sound stupid ), why is there an Lscript mailing list if they have a forum around here ??????

not sure: maybe because people like to access email for everything and dont like to go to a forum all the time. receipt info is more centralised and therefore convenient, i suppose. :)

Djamu
07-21-2004, 10:11 AM
K thanks again...

if you stumble upon a time, on a mail from Bob Hood concerning this "accumulation" or have any info on precalculating this using matrices ? - as I can bake the whole motion -

Then you'll be my hero ! :p

Karmacop
07-21-2004, 12:32 PM
The mailing list has been around forever, way before these forums. Most of the people on there don't seem to hang out here :p

Djamu
07-21-2004, 12:41 PM
Didn't know & although I've been using LW for years, I just "discovered":D the forums very recently

hahaha.....