Need Javascript example of switch/case for script node 
Author Message
 Need Javascript example of switch/case for script node

Hi,

Could some post an example of using the Javascript switch/case syntax in
a vrml Script node.  I can't figure out why my syntax doesn't work.
Here's what I have.

      function initialize() {
        generateTransform();

        switch (ptype) {
          case 'CYLINDER':
            ang = 0.;
            dlt = Math.PI/8.;
            for (i = 0; i <= 16; i++) {
              crossSection_changed[i] =
                new SFVec2f (rad1*Math.cos(ang), -rad1*Math.sin(ang));
              ang += dlt;
            }
            break;
          default :
            crossSection_changed[0] = new SFVec2f (0, 0);
            crossSection_changed[1] = new SFVec2f (.1, 0);
        }

ptype is SFString

Thanks,

--
Robert Lipman                |  (301) 975-3829

100 Bureau Drive, Stop 8630  |   http://www.*-*-*.com/
Gaithersburg, MD 20899-8630  |   http://www.*-*-*.com/



Sat, 07 Jul 2001 03:00:00 GMT  
 Need Javascript example of switch/case for script node

Quote:

> Could some post an example of using the Javascript switch/case syntax in
> a VRML Script node.  I can't figure out why my syntax doesn't work.

In VRML, the "javascript" identifier denotes ECMAScript, not JavaScript.
ECMAScript doesn't have a switch statement. Use if..else.

--
Braden N. McDaniel

<URI:http://www.endoframe.com>



Sat, 07 Jul 2001 03:00:00 GMT  
 Need Javascript example of switch/case for script node

Quote:


> > Could some post an example of using the Javascript switch/case syntax in
> > a VRML Script node.  I can't figure out why my syntax doesn't work.

> In VRML, the "javascript" identifier denotes ECMAScript, not JavaScript.
> ECMAScript doesn't have a switch statement. Use if..else.

Thanks.  Where can I find a language reference for ECMAscript?

--
Robert Lipman                |  (301) 975-3829

100 Bureau Drive, Stop 8630  |  http://math.nist.gov/mcsd/Staff/RLipman/
Gaithersburg, MD 20899-8630  |  http://www.bfrl.nist.gov/



Sun, 08 Jul 2001 03:00:00 GMT  
 Need Javascript example of switch/case for script node

Quote:



> > > Could some post an example of using the Javascript switch/case syntax in
> > > a VRML Script node.  I can't figure out why my syntax doesn't work.

> > In VRML, the "javascript" identifier denotes ECMAScript, not JavaScript.
> > ECMAScript doesn't have a switch statement. Use if..else.

> Thanks.  Where can I find a language reference for ECMAscript?

<URI:http://www.ecma.ch/stand/ecma-262.htm>

--
Braden N. McDaniel

<URI:http://www.endoframe.com>



Sun, 08 Jul 2001 03:00:00 GMT  
 Need Javascript example of switch/case for script node
Likely Braden wil be perfectly right, of course.
But following code works PERFECT for my using Win98/NS4.5/CP2.1:

function timerScript (v, t) {
    if (!v) {
        fase ++;
        print ('Fase ' + fase);
    }
    switch (fase) {
        case 1:
        startTurnBackTimer = t;
        break;
    case 2:
        startMoveTimer = t;
        break;
    case 3:
        startTurnTimer = t;
        break;
    case 4:
        fase = 0;
    }

Quote:
}

Success!

Antoni Dol

Quote:


> > Could some post an example of using the Javascript switch/case syntax in
> > a VRML Script node.  I can't figure out why my syntax doesn't work.

> In VRML, the "javascript" identifier denotes ECMAScript, not JavaScript.
> ECMAScript doesn't have a switch statement. Use if..else.

> --
> Braden N. McDaniel

> <URI:http://www.endoframe.com>



Sun, 08 Jul 2001 03:00:00 GMT  
 Need Javascript example of switch/case for script node

Quote:

> Likely Braden wil be perfectly right, of course.
> But following code works PERFECT for my using Win98/NS4.5/CP2.1:

> function timerScript (v, t) {
>     if (!v) {
>         fase ++;
>         print ('Fase ' + fase);
>     }
>     switch (fase) {
>         case 1:
>         startTurnBackTimer = t;
>         break;
>     case 2:
>         startMoveTimer = t;
>         break;
>     case 3:
>         startTurnTimer = t;
>         break;
>     case 4:
>         fase = 0;
>     }
> }

Interesting.

It is an unfortunate artifact of the timeline under which VRML97 was
standardized that we have a situation where the "javascript" identifier
can identify ECMAScript, but not JavaScript. Nonetheless, it's there,
and if you mix JavaScript-specific stuff in with your ECMAScript, you
will have non-conformant VRML. That may be okay for your particular
application, but IMO it is a bug in Cosmo Player that it allows this. I
think it should at least issue a warning.

If Cosmo Player wishes to support this and other JavaScript-specific
constructions, it should do so under a different identifier for the
script. Perhaps a version-labeled identifier would be appropriate (for
example, "javascript1.2").

Of course, that is the easy case... The real problems set in when one
tries to attack the issue of external JavaScript files. You can't use
the file extension ".js" for these files or the mime type
"application/x-javascript", because VRML has commandeerd these for use
with ECMAScript.

What a mess.

--
Braden N. McDaniel

<URI:http://www.endoframe.com>



Mon, 09 Jul 2001 03:00:00 GMT  
 Need Javascript example of switch/case for script node

Quote:

> It is an unfortunate artifact of the timeline under which VRML97 was
> standardized that we have a situation where the "javascript" identifier
> can identify ECMAScript, but not JavaScript. Nonetheless, it's there,
> and if you mix JavaScript-specific stuff in with your ECMAScript, you
> will have non-conformant VRML. That may be okay for your particular
> application, but IMO it is a bug in Cosmo Player that it allows this. I
> think it should at least issue a warning.

Incidentally, if you take a peek through the Netscape documentation
for their JavaScript (back through the historical archives) you'll
see that the switch construct wasn't always supported, so I've
taken that to mean that you shouldn't use it in webpages, either.

For true lovers of the degenerate -- and I know who you are -- check
http://home.hiwaay.net/~crispen/kellys_place/pop_quiz.html for the
world's ugliest IF.
--
Bob & Kelly Crispen

"And I observe, when any Yahoo comes from London out of Curiosity [to]
visit me at mine own House, we neither of us are able to deliver our
Conceptions in a Manner intelligible to the other."



Mon, 09 Jul 2001 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. switching sounds with switch node and script?

2. Script node: JavaScript vs. Java

3. Script Node: vrmlscript vs javascript - any differences ?

4. EAI: How to add nodes to the Switch{} node

5. Example of a SCRIPT node using JDBC?

6. example for Java in Script Nodes

7. Need example of working tcl/tk script used as cgi-bin script

8. Task Switch: code examples needed...

9. NEED HELP, Java script node and applet

10. Help Needed : Using native methods in Java Script Nodes in Netscape 4.0/Cosmo 2.0

11. Passing Nodes as arguments into JavaScript

12. Getting and Setting Node values from javascript

 

 
Powered by phpBB® Forum Software