Jacob Lenn Posted July 29, 2013 Posted July 29, 2013 XML: <zaladunki> <marker x="-1707.185546875" y="12.604281425476" z="3.5546875" type="cylinder" size="3" r="255" g="255" b="255" a="170" /> <marker x="158.99987792969" y="-22.182670593262" z=" 1.578125" type="cylinder" size="3" r="255" g="255" b="255" a="170" /> </zaladunki> How can i get random marker from this?
Castillo Posted July 29, 2013 Posted July 29, 2013 You must load the XML content using the XML functions, then use math.random.
Jacob Lenn Posted July 29, 2013 Author Posted July 29, 2013 I have this: function randomMarker () local markers = xmlLoadFile("zaladunki.xml") if markers then local childs = xmlNodeGetChildren(markers) for k,v in ipairs (childs) do -- what shud i put here? end end end
Castillo Posted July 29, 2013 Posted July 29, 2013 function randomMarker ( ) local markers = xmlLoadFile ( "zaladunki.xml" ) if ( markers ) then local childs = xmlNodeGetChildren ( markers ) local randomIndex = math.random ( #childs ) local child = childs [ randomIndex ] if ( child ) then -- Do something end end end
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now