Jump to content

[Help] New valid ID


Recommended Posts

Hello guys,

I'm having a little problem with this code, The problem is when every new object created it should give it new valid it

that is not used by another object the id will be Number.

NOTE: i'm using a 'split' cause i need it in the whole code.

 

My code:

local object = createObject (3095, 1557.835, 1575.586, 10.820)
setElementID (object, "1,Object")

function getFreeID ()
    local id = 0
    for _,v in ipairs (getElementsByType ("object", resourceRoot)) do
        local data = split (getElementID (v), ",")
        for i = 0, #getElementsByType ("object", resourceRoot) + 1 do
            if (data[1] == i) then
                id = id + 1
            end
        end
    end
    return id
end

 

Edited by #Black_Hawk
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...