Jump to content

element count


DakiLLa

Recommended Posts

#amountOfObjects=getElementsByType("object") 

The getElementsByType function should return a table. And # counts how many indexes a table has.

Your example doesn't make any sense. It's

amountOfObjects=#getElementsByType("object") 

Link to comment

ehm guys..one problem here.. i'm getting something other than amount of objects

addCommandHandler ( "test", 
    function (  ) 
        local objects = getElementsByType ( "object" ) 
        objAmount = #objects 
        for k,object in ipairs (objects) do 
            if getObjectModel (object) == 649 then 
                outputChatBox ( "We have "..objAmount.." objects" ) 
            end 
        end 
    end 
) 

if it's (for example) 4 objects i have next:

We have 805 objects

We have 805 objects

We have 805 objects

We have 805 objects

can you fix my mistakes ?

Link to comment
#amountOfObjects=getElementsByType("object") 

The getElementsByType function should return a table. And # counts how many indexes a table has.

Your example doesn't make any sense. It's

amountOfObjects=#getElementsByType("object") 

Kinda bad mistake of mine indeed lol...

Anyway, DaK, put "break" (without the quotes) in the line after outputChatBox. Should help.

Link to comment

ok, thx, it outputs only one message now. But another problem: my example counts all objects on server (thats why i have ~800 objects :?) , not only objects with ID 649.

How to count objects only with current id?

i have getObjectModel line but it placed in wrong place i think.

Link to comment

I already wondered what that for loop was for. :P

addCommandHandler ( "test", 
    function (  ) 
        local objects = getElementsByType ( "object" ) 
        local i=0 
        for k,object in ipairs (objects) do 
            if getObjectModel (object) == 649 then 
                i=i+1 
            end 
        end 
        outputChatBox ( "We have "..i.." objects with ID 649" ) 
    end 
) 

This should output the amount of objects with ID 649.

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