[M]ister Posted August 6, 2014 Share Posted August 6, 2014 Hello I am creating a system for teams and plan to use xml to save data from gangs. But I'm having some difficulty using it and I would do the following: Well I'm in the team 'Gang1' and type in the command ex: '/ gang tag ' and with this he change the value 'tag' of the xml file . gangs.xml <teams> <team name="Gang1" tag="TAG1" color="#FF9e00"></team> <team name="Gang2" tag="TAG2" color="#00FF00"></team> <team name="Gang3" tag="TAG3" color="#777777"></team> </teams> script.lua addCommandHandler("gang", function(player,cmd,subcmd,newtag) if subcmd == "tag" then -- help me with code ? end end) Could anyone help me with this? Link to comment
Bonsai Posted August 7, 2014 Share Posted August 7, 2014 I think the wiki has some nice examples how to use xml functions. Overall, its nothing to hard. Link to comment
Et-win Posted August 7, 2014 Share Posted August 7, 2014 xmlNodeGetChildren xmlNodeGetAttribute Link to comment
[M]ister Posted August 7, 2014 Author Share Posted August 7, 2014 It changes the value of the 'tag' in XML, but prints the message 'Error' twice addCommandHandler("gang", function(player,cmd,subcmd,newtag) if subcmd == "tag" then local xml = xmlLoadFile("gangs.xml") local children = xmlNodeGetChildren(xml) teams = {} for i,nodes in pairs(children) do teams[i] = xmlNodeGetAttribute(nodes,"name") if teams[i] == getTeamName(getPlayerTeam(player)) then xmlNodeSetAttribute(nodes,"tag",newtag) else outputChatBox("Error") end end xmlSaveFile(xml) xmlUnloadFile(xml) end end) Link to comment
[M]ister Posted August 7, 2014 Author Share Posted August 7, 2014 the 'Error' still continues to appear twice Link to comment
Et-win Posted August 7, 2014 Share Posted August 7, 2014 Never mind what I said about , I looked wrong. But why putting it into a table and not just a variable? Link to comment
[M]ister Posted August 7, 2014 Author Share Posted August 7, 2014 I had tried just with variables, but as the error persisted I decided to try several things '-' Link to comment
Et-win Posted August 7, 2014 Share Posted August 7, 2014 Well, it's this line atleast: if teams[i] == getTeamName(getPlayerTeam(player)) then Put 'getTeamName(getPlayerTeam(player))' into a variable and output it, also for 'teams' and check or they are both the same. 1 of these must be wrong. Link to comment
[M]ister Posted August 7, 2014 Author Share Posted August 7, 2014 addCommandHandler("gang", function(player,cmd,subcmd,newtag) if subcmd == "tag" then local xml = xmlLoadFile("gangs.xml") local children = xmlNodeGetChildren(xml) teams = {} for i,nodes in pairs(children) do teams[i] = xmlNodeGetAttribute(nodes,"name") teamName = getTeamName(getPlayerTeam(player)) outputChatBox("Team name in xml: "..teams[i].." Team name of player: "..teamName) if teams[i] == teamName then xmlNodeSetAttribute(nodes,"tag",newtag) --outputChatBox("You changed the tag") else --outputChatBox("Error") end end xmlSaveFile(xml) xmlUnloadFile(xml) end end) Link to comment
Bonsai Posted August 7, 2014 Share Posted August 7, 2014 Why do you store the team anyway? Couldn't you just go through all nodes, get the name, and compare with the team name? if xmlNodeGetAttribute(nodes,"name") == teamName then xmlNodeSetAttribute(nodes,"tag",newtag) return end Link to comment
Et-win Posted August 7, 2014 Share Posted August 7, 2014 Why do you store the team anyway? Couldn't you just go through all nodes, get the name, and compare with the team name? if xmlNodeGetAttribute(nodes,"name") == teamName then xmlNodeSetAttribute(nodes,"tag",newtag) return end Because it can return false. And why would you check something that failed? Check or it's false and if so output it, always handy for typos in XML file. 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