I have value of a variable in an object, how to select it?

I have lots of objects  on the screen and each of them has have unique id. example object.id = as62b4.

Now how do i select this object? say i want to change it’s position etc?

I thaught about putting all the objects in an array and go through all the objects in the array to match the id but in my case it won’t work because as i said i have lots of objects in the scene and it will be a very slow process and i want a fast solution.

Thanks in advance

You can put them into table (in lua there is only ‘table’ which acts both as C array, dynamic array and hash table (dictionary)) - or there is no other way to do it :P. Display objects are kept in variables as references so this won’t be as big as you may assume

u mean something like this…

local function findByName( name ) local resultArray = {} for i=1, #array do if array[i].name == name then resultArray[#resultArray+1] = array[i] end end return resultArray end

but as i said going through all object each frame of the game will make it very slow :frowning:

Any other alternatives???

Thanks Again!

As mentioned, Lua tables can be indexed, hashed or mixed type.

You can also use dictionary function of table if ids are unique

[lua]

local function findById( id )
     return resultArray[tostring(id)] – using tostring() because if number used, there will be missing spaces in table
end 

[/lua]

You can put them into table (in lua there is only ‘table’ which acts both as C array, dynamic array and hash table (dictionary)) - or there is no other way to do it :P. Display objects are kept in variables as references so this won’t be as big as you may assume

u mean something like this…

local function findByName( name ) local resultArray = {} for i=1, #array do if array[i].name == name then resultArray[#resultArray+1] = array[i] end end return resultArray end

but as i said going through all object each frame of the game will make it very slow :frowning:

Any other alternatives???

Thanks Again!

As mentioned, Lua tables can be indexed, hashed or mixed type.

You can also use dictionary function of table if ids are unique

[lua]

local function findById( id )
     return resultArray[tostring(id)] – using tostring() because if number used, there will be missing spaces in table
end 

[/lua]