<div dir="ltr">Thanks Andreas,  should help.<div><br>I note that the url field is not added to your code.  A start on url is in my code, but it's untested, and only processes first element in array.</div><div><br></div><div>In: NodeNameSpace.js, around line 559, I added the comparison to "x3dscript" to prevent warnings.  I am not sure if I should use the body of the condition or not.  The comparison may need to be on another branch of code:<br></div><div><br></div><div>        //silence warnings<br>        else if ( tagLC == "protodeclare" || tagLC == "externprotodeclare"<br>                || tagLC == "protoinstance" || tagLC == "x3dscript" )<br>        {<br>            n = null;<br>        }<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Oct 17, 2020 at 6:48 AM Andreas Plesch <<a href="mailto:andreasplesch@gmail.com">andreasplesch@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">Hi John,<br>
<br>
since I had started to sketch some answers I went ahead and implemented a rough draft of a X3DScript node for x3dom.<br>
<br>
Here is the basic spec. example working with the node:<br>
<br>
<a href="https://raw.githack.com/andreasplesch/x3dom/4cf1ec31736109e67d7b44aa1afb8fc8133f8cb6/test/regression-suite/test/cases/x3dscript/TouchSensorIsOverEventECMAScript.html" rel="noreferrer noreferrer" target="_blank">https://raw.githack.com/andreasplesch/x3dom/4cf1ec31736109e67d7b44aa1afb8fc8133f8cb6/test/regression-suite/test/cases/x3dscript/TouchSensorIsOverEventECMAScript.html</a><br>
<br>
Here is the implementation:<br>
<br>
<a href="https://github.com/andreasplesch/x3dom/blob/fields/src/nodes/Scripting/X3DScript.js" rel="noreferrer noreferrer" target="_blank">https://github.com/andreasplesch/x3dom/blob/fields/src/nodes/Scripting/X3DScript.js</a><br>
<br>
I am using "X3DScript" for now because it is less confusing. It should be possible to switch to Script type='app/x3dscript' at some point.<br>
<br>
It turns out that in html documents CDATA sections get converted into comments. This is great since it lets one use any character ( except for -->) in the script. So I am looking for converted comments under the script node for the script source.  I did not look into xhtml but xml should be easier.<br>
<br>
Since MDN also recommends Function over eval, I tried to go this way and could figure out an (unsafe) solution using wrappers to maintain the internal context of the script. I think the same approach may be possible for x_ite as well.<br>
<br>
I use the nice x_ite approach to get access to the functions in the script, by returning references to the functions.<br>
<br>Unlike x_ite I am trying not to use with() since it is not recommended. Instead I add lots of helpers to the script source in a preamble, I think like you do. For output fields x_ite is also using with() and getters and setters. For now, I am trying to avoid with() and just compare output field values before and after a script set function gets called, from a route. If there is a change, an event is fired.<br>
<br>
There is no attempt to deal with XFNode field values. This will be tricky. I did not test anything other than the simple example but other simple examples may start to work as well, perhaps with some adjustments to how SAI is used. Gears will need SFRotation which may be easy to add to the preamble.<br>
<br>
Cheers, -Andreasq<div>---on the phone---</div></div><br>
<br>
On Thu, Oct 15, 2020 at 10:31 PM John Carlson <<a href="mailto:yottzumm@gmail.com" rel="noreferrer" target="_blank">yottzumm@gmail.com</a>> wrote:<br>
><br>
><br>
><br>
> On Thu, Oct 15, 2020 at 9:25 PM John Carlson <<a href="mailto:yottzumm@gmail.com" rel="noreferrer" target="_blank">yottzumm@gmail.com</a>> wrote:<br>
>><br>
>> What I am searching for is:<br>
>><br>
>> 1. How to add Script related routes to X3DOM<br>
><br>
><br>
> Once I set up Script and fields, this is done automatically with setupTree?<br>
>  <br>
>><br>
>> 2. How to hook in Proto IS statements found in Scripts.<br>
><br>
><br>
> Not sure how to do that yet. <br>
>><br>
>> 3. How to modify any Script code to support parsing and the above.<br>
><br>
><br>
> adding any functions, declaring variables, etc. <br>
>><br>
>><br>
>> On Thu, Oct 15, 2020 at 9:15 PM John Carlson <<a href="mailto:yottzumm@gmail.com" rel="noreferrer" target="_blank">yottzumm@gmail.com</a>> wrote:<br>
>>><br>
>>> Something like<br>
>>><br>
>>> fromNode.setupRoute(fromField, toNode, toField);<br>
>>><br>
>>> ? That's only for routes?  What about events?<br>
>>><br>
>>> John<br>
>>><br>
>>><br>
>>> On Thu, Oct 15, 2020 at 8:42 PM John Carlson <<a href="mailto:yottzumm@gmail.com" rel="noreferrer" target="_blank">yottzumm@gmail.com</a>> wrote:<br>
>>>><br>
>>>><br>
>>>>>> Use the set_xfield functions on field_changed (xfield).<br>
>>>>><br>
>>>>><br>
>>>>> Not implemented.  Is this new code?   Where would I put it under Scripting/?   Can you provide a short example?<br>
>>>>>><br>
>>>>>><br>
>>>>>> Post messages for all _changed fields as given in the field def.<br>
>>>>>> Somehow deal with SFNode fields.<br>
>>>>>><br>
>>>>>><br>
>>>><br>
>>>> There is sample code under Script.js:<br>
>>>> <a href="https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/Script.js#L346" rel="noreferrer noreferrer" target="_blank">https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/Script.js#L346</a><br>
>>>><br>
>>>> Below:<br>
>>>> ====================================================================<br>
>>>>         doRoute(mypackage, fromNode, fromField, toNode, toField, log, set, changed, selector, url) {<br>
>>>>                 var fromScript = mypackage.find(fromNode);<br>
>>>>                 var toScript = mypackage.find(toNode);<br>
>>>>                 // only add routes with scripts involved<br>
>>>>                 if (typeof fromScript !== 'undefined' || typeof toScript !== 'undefined') {<br>
>>>>                         var from =                       this.nodeUtil(selector)+fromNode+"','"+fromField+"')";<br>
>>>>                         if (typeof fromScript !== 'undefined') {<br>
>>>>                                 from = 'typeof '+this.useX3DJSON('Obj', selector, url, fromScript.name)+'.'+fromField+changed+' === "function" ? '+this.useX3DJSON('Obj', selector, url, fromScript.name) + '.'+fromField+changed+'() : '+this.useX3DJSON('Obj', selector, url, fromScript.name) + '.'+fromField;<br>
>>>>                         }<br>
>>>>                         var to =                        this.nodeUtil(selector)+toNode+"','"+toField+"',";<br>
>>>>                         if (typeof toScript !== 'undefined') {<br>
>>>>                                 to = this.useX3DJSON('Obj', selector, url, toScript.name) + '.'+set+toField+'(';<br>
>>>>                         }<br>
>>>>                         if (typeof fromScript !== 'undefined' && typeof toScript !== 'undefined') {<br>
>>>>                                 log.log("               if ("+this.useX3DJSON('Obj', selector, url, toScript.name)+" && "+from+") {");<br>
>>>>                         }<br>
>>>>                         log.log("                       "+to+from+", __eventTime);");<br>
>>>>                         if (typeof fromScript !== 'undefined' && typeof toScript !== 'undefined') {<br>
>>>>                                 log.log("               }");<br>
>>>>                         }<br>
>>>>                 }<br>
>>>>         }<br>
>>>><br>
>>>>  ====================================================================<br>
>>>><br>
<br>
<br>
</blockquote></div>