Jump to content

[Help] Generating an ID


victormgons

Recommended Posts

Hi. I need to generate an ID using this code:

function generateIDForABase() 
  xml = xmlLoadFile("SavedBases.xml") 
  ID = 0 
  maxn = 0 
  number = 0 
  for i,node in pairs(xmlNodeGetChildren(xml)) do 
    maxn = i 
  end 
  for i,node in pairs(xmlNodeGetChildren(xml)) do 
    number = xmlNodeGetName(node):gsub('Base','') 
    numbers = tonumber(number) 
    ID = ID + 1 
    if numbers ~= i then 
      break 
    end 
  end 
  if ID == maxn and ID == tonumber(number) then 
    ID = ID + 1 
  end 
  return "Base"..ID 
end 

And the XML is

<config> 
  <Base1></Base1> 
  <Base2></Base2> 
</config> 

It's working, but, when I delete the ID 1, and add it again, the XML will be:

<config> 
  <Base2></Base2> 
  <Base1></Base1> 
</config> 

And the script says the ID 1 is not used, can anyone help me?

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...