<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 4.0//EN" "https://www.web3d.org/specifications/x3d-4.0.dtd">
<X3D profile='Immersive' version='4.0' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-4.0.xsd'>
  <head>
    <meta content='Scripting.x3d' name='title'/>
    <meta content='X3D encodings example: this Script node decides whether or not to open a bank vault given openVault and combinationEntered messages. To do this, it remembers whether or not the correct combination has been entered. The Script node combined with a Sphere, a TouchSensor and a Sound node to show how is works. When the pointing device is over the sphere, the combinationEntered eventIn of the Script is sent. Then, when the Sphere is touched (typically when the mouse button is pressed) the Script is sent the openVault eventIn. This generates the vaultUnlocked eventOut which starts a click sound.' name='description'/>
    <meta content='Don Brutzman and Joe Williams' name='creator'/>
    <meta content='1 June 2002' name='created'/>
    <meta content='28 September 2025' name='modified'/>
    <meta content='X3D encodings, ISO/IEC 19776-1.3, Part 1: XML encoding, Annex C.5 Scripting example' name='specificationSection'/>
    <meta content='https://www.web3d.org/specifications/X3Dv4Draft/ISO-IEC19776-1v4.0-CD/Part01/examples.html#ScriptingExample' name='specificationUrl'/>
    <meta content='https://www.web3d.org/x3d/content/examples/Basic/X3dSpecifications/Scripting.x3d' name='identifier'/>
    <meta content='X3D-Edit 4.0, https://www.web3d.org/x3d/tools/X3D-Edit' name='generator'/>
    <meta content='../license.html' name='license'/>
  </head>
  <Scene>
    <WorldInfo title='Scripting.x3d'/>
    <Script DEF='OpenVault'>
      <field accessType='inputOnly' name='openVault' type='SFTime'/>
      <field accessType='inputOnly' name='combinationEntered' type='SFBool'/>
      <field accessType='outputOnly' name='vaultUnlocked' type='SFTime'/>
      <field accessType='initializeOnly' name='unlocked' type='SFBool' value='false'/>
      <![CDATA[
ecmascript:
      function combinationEntered (value) {
        unlocked = value;
      }
      function openVault(value) {
      if (unlocked) vaultUnlocked = value;
      }
]]>
    </Script>
    <Shape>
      <Appearance>
        <Material diffuseColor='1 0 0'/>
      </Appearance>
      <Sphere/>
    </Shape>
    <Sound maxBack='1000' maxFront='1000' minBack='1000' minFront='1000'>
      <AudioClip DEF='Click' description='clicking sound' stopTime='1' url='"click.wav" "https://www.web3d.org/x3d/content/examples/Basic/X3dSpecifications/click.wav"'/>
    </Sound>
    <TouchSensor DEF='TS' description='touch to click'/>
    <ROUTE fromField='isOver' fromNode='TS' toField='combinationEntered' toNode='OpenVault'/>
    <ROUTE fromField='touchTime' fromNode='TS' toField='openVault' toNode='OpenVault'/>
    <ROUTE fromField='vaultUnlocked' fromNode='OpenVault' toField='startTime' toNode='Click'/>
  </Scene>
</X3D>