This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > VRML > January 2004 > something about script
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
something about script
|
|
| Unregistered 2004-01-13, 11:51 am |
| Hi,
I need some advice on vrmlscript. Below is just and example to illustrate the concept I am trying to express:
DEF ProcessTime Script {
eventIn SFTime set_time
eventOut SFTime time_changed
url “vrmlscript:
function set_time() {
for (I=0; I<10; I++)
time_changed = I + set_time;
}
}”
For this piece of code, I need time_changed to be sent as eventOut at every loop. However I noticed that time_changed can only be sent as eventOut after end of loop. I verify this by routing time_changed to another script which will print out the result when it receives as an eventIn and I only get the result print out at the end (only 1 result printed out). Can anyone tell me how can I cause time_changed to be sent as eventOut at every loop? To be specific, I want to have time_changed send as eventOut when I is between 0-9. However, the fact is, it only send as eventOut when I=9. Any suggestions? Thanks! | |
| Herbert Stocker 2004-01-14, 12:32 pm |
|
Unregistered wrote:quote:
> Hi,
>
> I need some advice on vrmlscript. Below is just and example to
> illustrate the concept I am trying to express:
>
> DEF ProcessTime Script {
>
> eventIn SFTime set_time
> eventOut SFTime time_changed
>
> url “vrmlscript:
> function set_time() {
>
> for (I=0; I<10; I++)
> time_changed = I + set_time;
> }
> }”
>
> For this piece of code, I need time_changed to be sent as eventOut at
> every loop. However I noticed that time_changed can only be sent as
> eventOut after end of loop. I verify this by routing time_changed to
> another script which will print out the result when it receives as an
> eventIn and I only get the result print out at the end (only 1 result
> printed out). Can anyone tell me how can I cause time_changed to be
> sent as eventOut at every loop? To be specific,
The VRML Spec says that a when a script function changes the value
of an eventOut this value is sent only after the function returns.
And if the function sets this value multiple times only the last
value is sent.
This makes implementation of Scripts easier and less expensive if
the Script Engine and the VRML Player are two separate pieces of
software. The Script Engine need not comunicate with the VRML
Player during script execution, only afterwards.
As far as i remember even if you use directOutput TRUE only the
last value is sent to the other node.
On the other hand, Contact does not conform to the spec in this
respect and acts as you expect.
I think if you don't use Contact you need to change the concept
of your code. E.g. send all values in an MFInt32 instead of an
SFInt32 and use the following code in the receiving Script node
to execute a function on every value:
for(var C= 0; C<val.length; C++ ) SomeFunction(val[C]);
If the receiving node is not a Script, i think it will depend only
of the last value of a series of value anyway.
quote:
> I want to have
> time_changed send as eventOut when I is between 0-9. However, the fact
> is, it only send as eventOut when I=9. Any suggestions? Thanks!
>
Exactly it's not sent when I=9, it is sent after the whole function
returns. More or less at the }" line. :-)
The order in which the eventOuts are set is of course to preserve.
Ahh, the last sentence brings me to some "solution" to your problem.
Nevertheless i doupt it will be usefull for you:
Use multiple eventOuts and connect them all with the same eventIn.
Like in:
DEF scr Script
{
eventOut SFInt32 firstValue
eventOut SFInt32 secondValue
eventOut SFInt32 thirdValue
url "vrmlscript:
function something(val)
{
firstValue= 1;
secondValue= 2;
thirdValue= 3;
}
"
}
ROUTE scr.firstValue TO Receiver.input
ROUTE scr.secondValue TO Receiver.input
ROUTE scr.thirdValue TO Receiver.input
Here there is a good chance that the eventIn Receiver.input
will receive all three numbers.
Herbert
--
Herbert Stocker (aka hersto)
http://www.hersto.de
www.bitmanagement.de
| |
| Joe D Williams 2004-01-14, 2:30 pm |
| > > > DEF ProcessTime Script {
quote:
of your code.
If this signal is for internal use - a script running in the world -
the VRML97 folks put in the TimeSensor, which does what you
wish without the need for this sort of continiously-running
script in the user code. Well, if you need a 'master' timer,
then you might need some scripting to start and stop 'slave'
timesensors.
For animation, please check the use of timesensors with
the various interpolator nodes.
For external use, you may with to send some sort of timing
signal into the world, and this is allowed using the VRML97 EAI
or x3d SAI and a program external to the world.
Thanks and Best Regards,
Joe
"Herbert Stocker" <hst-uzd-nospam@hersto.de> wrote in message
news:4005694F.8070400@hersto.de...[QUOTE][color=darkred]
>
>
> Unregistered wrote:
>
> The VRML Spec says that a when a script function changes the value
> of an eventOut this value is sent only after the function returns.
> And if the function sets this value multiple times only the last
> value is sent.
> This makes implementation of Scripts easier and less expensive if
> the Script Engine and the VRML Player are two separate pieces of
> software. The Script Engine need not comunicate with the VRML
> Player during script execution, only afterwards.
>
> As far as i remember even if you use directOutput TRUE only the
> last value is sent to the other node.
>
> On the other hand, Contact does not conform to the spec in this
> respect and acts as you expect.
>
> I think if you don't use Contact you need to change the concept
> of your code. E.g. send all values in an MFInt32 instead of an
> SFInt32 and use the following code in the receiving Script node
> to execute a function on every value:
> for(var C= 0; C<val.length; C++ ) SomeFunction(val[C]);
> If the receiving node is not a Script, i think it will depend only
> of the last value of a series of value anyway.
>
>
> Exactly it's not sent when I=9, it is sent after the whole function
> returns. More or less at the }" line. :-)
> The order in which the eventOuts are set is of course to preserve.
>
> Ahh, the last sentence brings me to some "solution" to your problem.
> Nevertheless i doupt it will be usefull for you:
>
> Use multiple eventOuts and connect them all with the same eventIn.
>
> Like in:
>
> DEF scr Script
> {
> eventOut SFInt32 firstValue
> eventOut SFInt32 secondValue
> eventOut SFInt32 thirdValue
>
> url "vrmlscript:
>
> function something(val)
> {
> firstValue= 1;
> secondValue= 2;
> thirdValue= 3;
> }
> "
> }
>
> ROUTE scr.firstValue TO Receiver.input
> ROUTE scr.secondValue TO Receiver.input
> ROUTE scr.thirdValue TO Receiver.input
>
>
> Here there is a good chance that the eventIn Receiver.input
> will receive all three numbers.
>
> Herbert
>
>
>
>
>
> --
> Herbert Stocker (aka hersto)
> http://www.hersto.de
> www.bitmanagement.de
>
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|