monumento Posted April 6, 2014 Share Posted April 6, 2014 Hello today. I have a small question. Im scripting a mini-missions system on my server and i have a problem. That's my .xml file with one mission: <2> EVAN 2 2> That's onClientPickupHit (cuz mission start when player enters the pickup) local function poczatekMisji(thePlayer) --build_Dialog() local id_pickupa = getElementData(source, "pickup.id") triggerServerEvent("rozpoczynaMisje", getLocalPlayer(), getLocalPlayer(), id_pickupa) end addEventHandler("onClientPickupHit", root, poczatekMisji) And the last one... i guess the problem is there, but i cant resolve it somehow. function rozpoczynaMisje (kto, pickupid) local plik = xmlLoadFile("quests/misje.xml") local zapisz = xmlFindChild(plik, "2",0) local kto_da = xmlFindChild(zapisz, "kto_daje",0) local pickupek = xmlFindChild(zapisz, "pickupid",0) local ktodaje = xmlNodeGetValue(kto_da) outputChatBox(tostring(ktodaje)) end addEvent( "rozpoczynaMisje", true ) addEventHandler( "rozpoczynaMisje", root, rozpoczynaMisje ) Errors: WARNING: BAD ARGUMENT @ `xmlFindChild` WARNING: BAD ARGUMENT @ `xmlFindChild` WARNING: BAD ARGUMENT @ `xmlFindChild` WARNING: BAD ARGUMENT @ `xmlNodeGetValue` The funnier thingwhen i did local plik = xmlLoadFile("quests/misje.xml") if plik then outputChatBox("test.") end It wont work, haha. The funniest thing. In same resource i have: function dodajMisje (kto,kto_daje,pickupid,opis) local plik = xmlLoadFile("quests/misje.xml") local zapisz = xmlCreateChild(plik, tostring(pickupid)) local kto_da = xmlCreateChild(zapisz, "kto_daje") local pickupek = xmlCreateChild(zapisz, "pickupid") local opisek = xmlCreateChild(zapisz, "opis") xmlNodeSetValue(kto_da, kto_daje) xmlNodeSetValue(pickupek, pickupid) xmlNodeSetValue(opisek, opis) xmlSaveFile(plik) xmlUnloadFile(plik) end Works perfectly. Link to comment
Moderators Citizen Posted April 6, 2014 Moderators Share Posted April 6, 2014 <2>2> XML tags must always start with a letter. Link to comment
monumento Posted April 6, 2014 Author Share Posted April 6, 2014 Thanks, now the saving works. I did it by this way: local nowy = xmlCreateChild(p_misje, "pickup"..tostring(pickupid)) Now. I want to get values (in other script, same resource) CLIENT-SIDE: function poczatekMisji(thePlayer) --build_Dialog() local id_pickupa = getElementData(source, "pickup.id") triggerServerEvent("rozpoczynaMisje", getLocalPlayer(), id_pickupa) end addEventHandler("onClientPickupHit", root, poczatekMisji) SERVER-SIDE: function rozpoczynaMisje (pickupid) local pliczek = xmlLoadFile("quests/misje.xml") local zapisz = xmlFindChild(pliczek, "pickup"..tostring(pickupid)) local kto_da = xmlFindChild(zapisz, "imie") local pickupek = xmlFindChild(zapisz, "pickupid") local ktodaje = xmlNodeGetValue(kto_da) outputChatBox(ktodaje) end addEvent( "rozpoczynaMisje", true ) addEventHandler( "rozpoczynaMisje", getRootElement(), rozpoczynaMisje ) And... WARNING: BAD ARGUMENT @ XMLFINDCHILD WARNING: BAD ARGUMENT @ XMLFINDCHILD WARNING: BAD ARGUMENT @ XMLFINDCHILD WARNING: BAD ARGUMENT @ XMLNODEGETVALUE WARNING: BAD ARGUMENT @ OUTPUTCHATBOX [EXPECTED STRING AT ARGUMENT 1, GOT BOOLEAN] How the file looks: Evan 1 Evanowicz 2 Hmm? Seems it again wont load the file. Link to comment
monumento Posted April 7, 2014 Author Share Posted April 7, 2014 bumping up, guys. help me Link to comment
Moderators Citizen Posted April 7, 2014 Moderators Share Posted April 7, 2014 Well, your xmlLoadFile is obviously failing to open your xml file. Make sure the path is correct and that there is no typo in the filename (check it in the saving function). It's also highly recommended to unload the xml file once you are done with it: function rozpoczynaMisje (pickupid) local pliczek = xmlLoadFile("quests/misje.xml") if pliczek then local zapisz = xmlFindChild(pliczek, "pickup"..tostring(pickupid)) local kto_da = xmlFindChild(zapisz, "imie") local pickupek = xmlFindChild(zapisz, "pickupid") local ktodaje = xmlNodeGetValue(kto_da) outputChatBox(ktodaje) xmlUnloadFile(pliczek) --unload the file if it has been loaded else outputDebugString("[ERROR] Couldn't open 'quests/misje.xml'") end end addEvent( "rozpoczynaMisje", true ) addEventHandler( "rozpoczynaMisje", getRootElement(), rozpoczynaMisje ) So do the same with in your saving function. Link to comment
monumento Posted April 8, 2014 Author Share Posted April 8, 2014 I fixed it. My mistake. Thanks for your help! Link to comment
Moderators Citizen Posted April 8, 2014 Moderators Share Posted April 8, 2014 No problem, have fun coding your server Link to comment
Saml1er Posted April 8, 2014 Share Posted April 8, 2014 I'd suggest you to unload the file after the at after end because you sometimes it might take time to load the file and you'll face errors ( I'm saying this because I myself have experienced this. ) function rozpoczynaMisje (pickupid) local pliczek = xmlLoadFile("quests/misje.xml") if pliczek then local zapisz = xmlFindChild(pliczek, "pickup"..tostring(pickupid)) local kto_da = xmlFindChild(zapisz, "imie") local pickupek = xmlFindChild(zapisz, "pickupid") local ktodaje = xmlNodeGetValue(kto_da) else outputDebugString("[ERROR] Couldn't open 'quests/misje.xml'") end xmlUnloadFile(pliczek) -- unloading it after you're completely done with xml functions because you never know what happens. end Link to comment
Moderators Citizen Posted April 9, 2014 Moderators Share Posted April 9, 2014 function rozpoczynaMisje (pickupid) local pliczek = xmlLoadFile("quests/misje.xml") if pliczek then local zapisz = xmlFindChild(pliczek, "pickup"..tostring(pickupid)) local kto_da = xmlFindChild(zapisz, "imie") local pickupek = xmlFindChild(zapisz, "pickupid") local ktodaje = xmlNodeGetValue(kto_da) else outputDebugString("[ERROR] Couldn't open 'quests/misje.xml'") end xmlUnloadFile(pliczek) -- unloading it after you're completely done with xml functions because you never know what happens. end You know you just introduced a bug into this script ??? The version I did was already unloading it after all xml functions ... By doing it in your way, if xmlLoadFile returns false for some reason, you will still try to unload that file: xmlUnloadFile( false ) So it will throw an error like this: Bad argument @xmlUnloadFile [Expected element, got boolean] or something similar to this. Link to comment
Saml1er Posted April 10, 2014 Share Posted April 10, 2014 function rozpoczynaMisje (pickupid) local pliczek = xmlLoadFile("quests/misje.xml") if pliczek then local zapisz = xmlFindChild(pliczek, "pickup"..tostring(pickupid)) local kto_da = xmlFindChild(zapisz, "imie") local pickupek = xmlFindChild(zapisz, "pickupid") local ktodaje = xmlNodeGetValue(kto_da) else outputDebugString("[ERROR] Couldn't open 'quests/misje.xml'") end xmlUnloadFile(pliczek) -- unloading it after you're completely done with xml functions because you never know what happens. end You know you just introduced a bug into this script ??? The version I did was already unloading it after all xml functions ... By doing it in your way, if xmlLoadFile returns false for some reason, you will still try to unload that file: xmlUnloadFile( false ) So it will throw an error like this: Bad argument @xmlUnloadFile [Expected element, got boolean] or something similar to this. I tested it and it works. Link to comment
Moderators Citizen Posted April 10, 2014 Moderators Share Posted April 10, 2014 I tested it and it works. Did you really what I said ?? Of course it will works but only if xmlLoadFile doesn't return false ! Imagine if this file doesn't exist anymore/yet ? It won't work and the server will throw an error on xmlUnloadFile. My version is doing the same except that it will not try to unload a file it couldn't load (that would be stupid). Do you understand ? If the file couldn't be loaded, then there is no need to unload it ! More, you SHOULDN'T try to unload it ! Link to comment
Saml1er Posted April 10, 2014 Share Posted April 10, 2014 I tested it and it works. if xmlLoadFile doesn't return false ! I misread it. I thought you said xmlUnloadFile but do you really think that it will be 100 % successful in this way? XML functions are laggy when you loop through huge data like in map files and when you loop through its children and getAttributes then you'll understand why I chose to unload it at the end. I don't have any reason to argue with you if you don't like my idea then just ignore it. 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