Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript loop not completing
    primarykey
    data
    text
    <p><strong>Solved</strong>-My code didn't use var in all of the places it should. Adding this resolves the issue.</p> <p>I'm trying to use a loop to go through the children nodes of a given "scene". In this example, it's scene 2. My code allows for "links" which essentially go and load the child nodes of another scene before coming back to the current scene and loading the remaining child nodes. The problem is, anytime I use a link, it will prevent the ORIGINAL scene from completing its loading.</p> <p><strong>XML:</strong></p> <pre><code>&lt;scene id="2"&gt; &lt;content&gt;Scene2-Content1&lt;/content&gt; &lt;content&gt;Scene2-Content2&lt;/content&gt; &lt;link id="4"/&gt; &lt;choice content="Scene2-Choice1"/&gt; &lt;/scene&gt; &lt;scene id="4"&gt; &lt;content&gt;Scene4-Content1&lt;/content&gt; &lt;choice content="Scene4-Choice1"/&gt; &lt;/scene&gt; </code></pre> <p><strong>JavaScript:</strong></p> <pre><code>var app = { loadScene: function (scene) { //find the scene and load the scene data if(app.storyXml != null) { sceneNodes = app.storyXml.getElementsByTagName("scene"); for(i=0; i&lt;sceneNodes.length; i++) { id = sceneNodes[i].getAttribute("id"); if(id == scene) { app.loadSceneData(sceneNodes[i]); break; } } } }, loadSceneData: function (scene) { childNodes = scene.childNodes; try { length = childNodes.length; for(i=0; i&lt;childNodes.length; i++) { console.log((i+1)+"/"+childNodes.length); tag = childNodes[i].tagName; if(tag == "content") app.loadSceneContent(childNodes[i]); if(tag == "link") app.loadSceneLink(childNodes[i]); if(tag == "choice") app.loadSceneChoice(childNodes[i]); } } catch(err) { console.log(err); } }, loadSceneLink: function (node) { if(app.storyXml != null) { sceneNodes = app.storyXml.getElementsByTagName("scene"); for(i=0; i&lt;sceneNodes.length; i++) { id = sceneNodes[i].getAttribute("id"); if(id == node.getAttribute("id")) { app.loadSceneData(sceneNodes[i]); break; } } } } } //loadSceneContent and loadSceneChoice omitted--they simply add some elements to the page. </code></pre> <p>In this specific example, loadSceneContent/loadSceneChoice are called for the first two content nodes in scene 2. After that, the link calls them for the content/choice node. I expect the control to return to the original loadSceneData loop, but it instead simply jumps to the end of the loop in the original loadSceneData call. I've banged my head against the wall and tried every variation I could think of. Nothing seems to work.</p> <p>If I remove the link node, everything from scene 2 is loaded as expected.</p> <p>I don't post on Stack Overflow often, so please let me know if I'm missing something essential to my question. I appreciate your help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload