Taalasmaa Posted March 20, 2010 Share Posted March 20, 2010 Yo, I'm very and I mean very newbie in XML. I can script lua very well, but I'm not ever practised XML's. I'm just testing this: function test2(thePlayer) mission = xmlLoadFile("test.xml") local newFinish = xmlCreateChild(mission, "newMission" ); x,y,z = getElementPosition(thePlayer) xmlNodeSetAttribute( newFinish, "posX", x ); xmlNodeSetAttribute( newFinish, "posY", y ); xmlNodeSetAttribute( newFinish, "posZ", z ); end addCommandHandler("test", test2) Why this isn't working. In debugscript it's giving Bad Arguement @ xmlCreateChild, Bad Arguement @ xmlNodeSetAttribute Thanks. Link to comment
Gamesnert Posted March 20, 2010 Share Posted March 20, 2010 xmlNodeSetAttribute fails because xmlCreateChild fails. xmlCreateChild seems ok, though. So I'm expecting that for some reason, test.xml couldn't be loaded. Perhaps you haven't this file yet? Or perhaps you've just got the wrong name / directory? Link to comment
Taalasmaa Posted March 20, 2010 Author Share Posted March 20, 2010 xmlNodeSetAttribute fails because xmlCreateChild fails.xmlCreateChild seems ok, though. So I'm expecting that for some reason, test.xml couldn't be loaded. Perhaps you haven't this file yet? Or perhaps you've just got the wrong name / directory? test.xml is in the same directory than the script itself. Name is test.xml And I got the file, so far. Also I checked that test.xml doesn't have any big letters like "Test.xml"- Link to comment
Gamesnert Posted March 20, 2010 Share Posted March 20, 2010 test.xml is in the same directory than the script itself. The only thing I can think of then is an error in the XML file. Link to comment
karlis Posted March 20, 2010 Share Posted March 20, 2010 might xml file dont get rootnode? and u need specify parentnode for xmlcreatechild, not xml file itself i think try if not mission then xmlCreateFile("test.xml","rootnode") end Link to comment
Taalasmaa Posted March 20, 2010 Author Share Posted March 20, 2010 might xml file dont get rootnode?and u need specify parentnode for xmlcreatechild, not xml file itself i think try if not mission then xmlCreateFile("test.xml","rootnode") end Still not working . Any other things? Link to comment
Taalasmaa Posted March 20, 2010 Author Share Posted March 20, 2010 Really weird.. I added resourceRoot = getResourceRootElement( getThisResource( ) ) addEventHandler("onResourceStart", resourceRoot, function( ) local mission = xmlCreateFile ( "test.xml", "root" ); outputChatBox("test.xml created succesfully") end ) and removed old test.xml for test, but it's not EVEN creating new test.xml Link to comment
Gamesnert Posted March 20, 2010 Share Posted March 20, 2010 This function creates a new XML document, which can later be saved to a file by using xmlSaveFile. This function will overwrite the file specified if it already exists. Explanations, big or small, the Wiki has it all. Link to comment
Taalasmaa Posted March 20, 2010 Author Share Posted March 20, 2010 This function creates a new XML document, which can later be saved to a file by using xmlSaveFile. This function will overwrite the file specified if it already exists. function test2() if not xmlLoadFile( "test.xml" ) then local mission = xmlCreateFile ( "test.xml", "root" ); local new1 = xmlCreateChild( mission, "newFinish" ); xmlSaveFile( mission ); end end addCommandHandler("test", test2) Tried this too. It only Gives <root/> To test.xml file. It's not creating "newFinish". Link to comment
Gamesnert Posted March 20, 2010 Share Posted March 20, 2010 Debug it, check what xmlCreateChild returns. Link to comment
Taalasmaa Posted March 20, 2010 Author Share Posted March 20, 2010 function test2() if not xmlLoadFile( "test.xml" ) then local mission = xmlCreateFile ( "test.xml", "root" ); local new1 = xmlCreateChild( mission, "Car" ); vehicle = getPedOccupiedVehicle(source) xmlNodeSetAttribute( new1, "Veh", vehicle ); xmlSaveFile( mission ); end end addCommandHandler("test", test2) Okay, tried this1 too, now. It's not giving ANY errors in debugscript.. Just shows in test.xml. And, I was in a car, lol. Link to comment
Taalasmaa Posted March 20, 2010 Author Share Posted March 20, 2010 I got it working. Thanks anyway for everyone who helped me :b! Link to comment
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