[x3d-public] internal script state

Andreas Plesch andreasplesch at gmail.com
Fri Nov 3 21:39:52 PDT 2017


Working on a ScalarSequencer proto ,I developed the script which
provides the functionality:

https://ripe-taxi.glitch.me/

It seems to work ok using x_ite. In order to maintain internal,
persisting state, the script uses an initializeOnly field:

https://glitch.com/edit/#!/ripe-taxi?path=index.html:161:21

Perhaps this is the intended use of such a field but I was wondering
if there are other standard ways to have such internal state storage.
For example, it may be convenient to use a javascript object for state
which could not be a field value.

It is possible to just use a global variable, initialized in the
initialize() function. However, in an environment such as web page
this would intrude other script sharing the global context. One could
use a namespace then, say script1.globalA

With x_ite it is possible declare a scoped variable in the script but
outside the functions which then persists and is in the scope of all
script functions but out of scope anywhere outside the script. A good
solution but likely this is not guaranteed to work in other browsers
since the spec. does not cover code execution outside the script
functions.

Perhaps the namespaced global variable would be the most standard way
but it would be great if global variables could be avoided.

-Andreas

-- 
Andreas Plesch
Waltham, MA 02453



More information about the x3d-public mailing list