This is me being curious again, about a behavior I observed while writing and testing some code.
I am just about finished writing another XML parsing routine, to load another section of data from my XML database and something I like to do as I code is test in very small increments..
For example, I write a few lines to grab an XML node pointer, and then debug some data about it (node path, node name, node data, etc) and then continue on if its working..
So in the process of writing this, I was writing a nested While loop setup (2 loops), and mistakenly I put my debug statement inside the loops; Inside one of the loops there is an IF/ENDIF block of logic that I use to identify the node I am in and this is where I noticed the weird behavior..
Basically the loop tests for a node, if its not there, it tests for the other. I probably lack the experience to know a more elegant solution, but in this case both IF conditions will eventually be true and code will be executed, grabbing element values and assigning them to variables.
Here is the section, for reference:
Code: Select all
Procedure Load_AreaMap()
;// Load the Area Map for matching Area location strings
;// to room address coordinates, to be printed as part of
;// the room title in the game.
nodepath$ = "/GameDatabase/AreaMap/" ;// Define the node path to search for Subnodes from.
*MainNode = MainXMLNode(XML_File) ;// Establish the root XML node of the database XML file.
*MainNode = XMLNodeFromPath(*MainNode, nodepath$) ;// Set the node path to search for Area Names in the Database from.
Debug XMLNodePath(*MainNode) ;// Echo the Node Path to the Debug Window for verification.
*ChildNode = ChildXMLNode(*MainNode)
Debug GetXMLNodeName(*ChildNode)
While *ChildNode <> 0 ;// Do stuff every time we fine a <Area> XML Element.
*SubNode = ChildXMLNode(*ChildNode) ;// Navigating down to the <Name> Element we need to load.
While *SubNode <> 0 ;// Still more navigating.
CurrentNode.s = GetXMLNodeName(*SubNode) ;// Get the name of the current Node we're in.
If CurrentNode = "id" ;// Once we have the Node we need...
AreaID.s = GetXMLNodeText(*SubNode) ;// Area ID doubles as Map Key
ElseIf CurrentNode = "Name" ;// Get the next node we need.
AreaName.s = GetXMLNodeText(*SubNode) ;// Get the name of the Area we are assigning to the Area ID.
EndIf
*SubNode = NextXMLNode(*SubNode)
;Debug "Area ID: #" + AreaID + " = " + AreaName
Wend
*ChildNode = NextXMLNode(*ChildNode)
AreaMap(AreaID) = AreaName
Wend
ForEach AreaMap()
Debug "Area Name is: " + AreaMap() + ", and it is Area ID#: " +MapKey(AreaMap())
Next
EndProcedure
Code: Select all
/GameDatabase/AreaMap
Area
Area ID: #1 =
Area ID: #1 = Kirkhill
Area ID: #2 = Kirkhill
Area ID: #2 = The Sleeping Forest
Area ID: #3 = The Sleeping Forest
Area ID: #3 = Secret Base
Area Name is: Kirkhill, and it is Area ID#: 1
Area Name is: The Sleeping Forest, and it is Area ID#: 2
Area Name is: Secret Base, and it is Area ID#: 3
Anyone else ever done something stupid like this?