Jump to content

xml problem


Castillo

Recommended Posts

hi there, i've got a error in a function using xml, its suposed to return the id he gets then do +1 every time i execute the function but it doesn't works, keeps returning id 0 every time.

my code:

function getCarCount (player) 
  local root = getResourceConfig("data.xml") 
  local index = getCarIndex (getAccountName(getPlayerAccount(player)),root) 
  if index then 
    local accountRoot = xmlFindChild (root,"user",index) 
    local idsRoot = xmlFindChild (accountRoot,"car",index) 
    local allIds = #xmlNodeGetChildren (idsRoot) 
    return allIds 
  end 
  xmlUnloadFile (root)   
end 

Tanks in advance.

Link to comment

1: Don't use return before you really want to end the function. Use it at least. Now you are returning, which means "stopping" too, before xmlUnloadFile gets called.

2: Where's the +1 you are talking about?

3: try my weird change:

  
function getCarCount (player) 
    local allIds = 0 
    local root = getResourceConfig("data.xml") 
    local index = getCarIndex (getAccountName(getPlayerAccount(player)),root) 
    if index then 
        local accountRoot = xmlFindChild (root,"user",index) 
        local idsRoot = xmlFindChild (accountRoot,"car",index) 
        allIds = xmlNodeGetChildren (idsRoot) -- Removed the #, idk if that will 
    end 
    xmlUnloadFile (root) 
    return #allIds -- Heres the # again, idk if this returns 0 if theres no table =/ 
end 
  

Link to comment

i'm afraid the problem still here,

look:

  
<playercars> 
    <user account="Snake"> 
        <car name="415" price="50000" id="0" /> 
        <car name="415" price="50000" id="0" /> 
    </user> 
</playercars> 

as you can see it gives same id to every car i buy :|

Link to comment

still no sign of any «index+1» or xmlCreateChild.

and you've posted XML with 0's but not the part which writes the XML itself

and:

      
local idsRoot = xmlFindChild (accountRoot,"car",index) 
local allIds = #xmlNodeGetChildren (idsRoot) 

here you're getting some car node and the trying to get it's children, which it doesnt have.

well, judging by XML you've posted.

Link to comment

thanks alot Aiboforcen, i will post the working code here (maybe someone in future gets same error :D)

function getCarCount (player) 
    local allIds = 0 
    local root = getResourceConfig("data.xml") 
    local index = getCarIndex (getAccountName(getPlayerAccount(player)),root) 
    if index then 
    local accountRoot = xmlFindChild (root,"user",index) 
    allIds = xmlNodeGetChildren (accountRoot) 
    end 
    xmlUnloadFile (root) 
    return #allIds 
end 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...