Java in VRML code...need help...or need a piano/keyborad.wrl 
Author Message
 Java in VRML code...need help...or need a piano/keyborad.wrl

I have 2 events from the AudioClip (of sound node)
routed to a script.

    isActive   is routed to   set_boolean  of the script
    description  is routed to   set_string2  of the script

I know the isActive to set_boolean works ok but the
description (SFSstring field) does not seem to works, ie the
check condition in the script:   if ( value == 'a' )
is never true. I also tried: if ( value == "a" )
The value in the description audio section is the character "a".
Is there someting wrong with my check? See a copy of the
script below.
All I am really trying to do is to identify a specific object
to the script when that object is clicked (using a touch sensor).
I just tried to pass in the description in the associated
audio to identify the object (I want to create a 3D keyboard,
when keys touched the correct sound is made & I need to know what key
was pressed). Is there any way to
identify an object that was clicked? (just routing a boolean true/false
is no use, I need to specifically identify each key).

Any help would be great. If you know of a piano/keyboard
vrml world that I can use that would be better!.

Thanks,
Danny

DEF counter Script {
  eventIn      SFBool set_boolean
  eventIn      SFString set_string2
  eventOut     SFBool choice1_changed
  eventOut     SFBool choice2_changed
  eventOut     SFString string_changed2
  field        SFBool value FALSE
  url "javascript:

// Handler for event set_string of type MFString.
function set_boolean ( bool, eventTime )
{      //if ( bool == true ) { choice1_changed = true; }

Quote:
}

// Handler for event set_string2 of type SFString.
function set_string2 ( value, eventTime )

{
           if ( value == 'a' ) { choice1_changed = true; }

Quote:
}

"
  mustEvaluate FALSE
  directOutput FALSE
Quote:
}



Sun, 10 Feb 2002 03:00:00 GMT  
 Java in VRML code...need help...or need a piano/keyborad.wrl
Hi Daniel,

There is nothing wrong with "if (value == 'a')". You should not use
double quotes (without escaping it) lest they are confused with the
Script url's double quotes.

I guess the other possible area to look for the solution is how you
ROUTE your string to set_string2. I doubt it will work if you just
code

ROUTE audio.description TO counter.set_string2

Try generating an explicit SFString eventOut to counter.set_string2.

---
yong bing

Quote:
> I have 2 events from the AudioClip (of sound node)
> routed to a script.
>     isActive   is routed to   set_boolean  of the script
>     description  is routed to   set_string2  of the script
> I know the isActive to set_boolean works ok but the
> description (SFSstring field) does not seem to works, ie the
> check condition in the script:   if ( value == 'a' )
> is never true. I also tried: if ( value == "a" )
> The value in the description audio section is the character "a".
> Is there someting wrong with my check? See a copy of the
> script below.
> All I am really trying to do is to identify a specific object
> to the script when that object is clicked (using a touch sensor).
> I just tried to pass in the description in the associated
> audio to identify the object (I want to create a 3D keyboard,
> when keys touched the correct sound is made & I need to know what key
> was pressed). Is there any way to
> identify an object that was clicked? (just routing a boolean true/false
> is no use, I need to specifically identify each key).
> Any help would be great. If you know of a piano/keyboard
> VRML world that I can use that would be better!.
> Thanks,
> Danny
> DEF counter Script {
>   eventIn      SFBool set_boolean
>   eventIn      SFString set_string2
>   eventOut     SFBool choice1_changed
>   eventOut     SFBool choice2_changed
>   eventOut     SFString string_changed2
>   field        SFBool value FALSE
>   url "javascript:
> // Handler for event set_string of type MFString.
> function set_boolean ( bool, eventTime )
> {      //if ( bool == true ) { choice1_changed = true; }
> }
> // Handler for event set_string2 of type SFString.
> function set_string2 ( value, eventTime )
> {
>            if ( value == 'a' ) { choice1_changed = true; }
> }
> "
>   mustEvaluate FALSE
>   directOutput FALSE
> }



Mon, 11 Feb 2002 03:00:00 GMT  
 Java in VRML code...need help...or need a piano/keyborad.wrl

Quote:

> I have 2 events from the AudioClip (of sound node)
> routed to a script.

>     isActive   is routed to   set_boolean  of the script
>     description  is routed to   set_string2  of the script

> I know the isActive to set_boolean works ok but the
> description (SFSstring field) does not seem to works, ie the
> check condition in the script:   if ( value == 'a' )
> is never true. I also tried: if ( value == "a" )
> The value in the description audio section is the character "a".
> Is there someting wrong with my check? See a copy of the
> script below.
> All I am really trying to do is to identify a specific object
> to the script when that object is clicked (using a touch sensor).
> I just tried to pass in the description in the associated
> audio to identify the object (I want to create a 3D keyboard,
> when keys touched the correct sound is made & I need to know what key
> was pressed). Is there any way to
> identify an object that was clicked? (just routing a boolean true/false
> is no use, I need to specifically identify each key).

> Any help would be great. If you know of a piano/keyboard
> VRML world that I can use that would be better!.

> Thanks,
> Danny

> DEF counter Script {
>   eventIn      SFBool set_boolean
>   eventIn      SFString set_string2
>   eventOut     SFBool choice1_changed
>   eventOut     SFBool choice2_changed
>   eventOut     SFString string_changed2
>   field        SFBool value FALSE
>   url "javascript:

> // Handler for event set_string of type MFString.
> function set_boolean ( bool, eventTime )
> {      //if ( bool == true ) { choice1_changed = true; }

> }
> // Handler for event set_string2 of type SFString.
> function set_string2 ( value, eventTime )

> {
>            if ( value == 'a' ) { choice1_changed = true; }
> }
> "
>   mustEvaluate FALSE
>   directOutput FALSE
> }

I just made a VRML piano but the keyboard is just one octave. I used a
touchsensor for each key and I don't need to know which key is pressed but
maybe viewing my code might give you some ideas.

http://members.ync.net/ecubed/index.htm

Good luck!

Ernest



Mon, 11 Feb 2002 03:00:00 GMT  
 Java in VRML code...need help...or need a piano/keyborad.wrl
Hi Yong,

 Thank for your reply. I am not a total VRML expert either as I use
CosmoWorlds VRML builder to build my worlds.
The routing code generated by Cosmo is:

ROUTE _12.isActive TO counter.set_boolean
ROUTE _12.description_changed TO counter.set_string2

I also manually modified the code at the 2nd line and tried:

   ROUTE _12.description TO counter.set_string2

and this did not work either. Is this what your reply suggested (Cosmo
generated anyway)?.

Is there ANY other way to specifically identify the output from a
group of shapes when touched (using TouchSensor)?. The only outputs
I can think of are just boolean true&false, and times. I need to know WHICH
shape
was touched (thats why I tried to use the description in the AudioClip).



Mon, 11 Feb 2002 03:00:00 GMT  
 Java in VRML code...need help...or need a piano/keyborad.wrl

Quote:

> Hi Yong,
>  Thank for your reply. I am not a total VRML expert either as I use
> CosmoWorlds VRML builder to build my worlds.
> The routing code generated by Cosmo is:
> ROUTE _12.isActive TO counter.set_boolean
> ROUTE _12.description_changed TO counter.set_string2
> I also manually modified the code at the 2nd line and tried:
>    ROUTE _12.description TO counter.set_string2
> and this did not work either. Is this what your reply suggested (Cosmo
> generated anyway)?.

Hi Daniel,

No, I don't think that will not work.
However, I suggest that you try another easier method if you don't mind
coupling your script to your AudioClip:

DEF counter Script {
  field SFNode audio USE _12           # assume _12 is your AudioClip
  field SFString string2 ""
  eventIn SFBool isActive

  url ["vrmlscript:
    ...
    function isActive(value) {
      if (!value) { // when value is true
        string2 = audio.description_changed;
      }
    }

    ...
  "]

Quote:
}



Wed, 13 Feb 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Help Needed Simple Java control of VRML

2. Newbie needs help in VRML and java

3. Connecting Java and VRML: Newcomer needing HELP!

4. Need help with my VRML code

5. help I need my wrl's

6. Needing the Java VRML Package

7. Southeastern Simulation Conference needs VRML/Java papers

8. Need Help: Converting Clarion DOS Code to CW Code

9. Please Help - Need to Convert Fortran Code to C Code

10. Please Help - Need to Convert Fortran Code to C Code

11. Code Listings Need for VRML 2.0

12. VRML Code needed

 

 
Powered by phpBB® Forum Software