Jump to content

[HELP] Tables


Recommended Posts

Hey guys, I need some help, it's my first time working with tables, I want to understand how it really works..

I have these 2 local variable, the first one gets the gang that owns the gangzone, and the second gets all members from this group (online and offline members) or at least it should get.

My problem is this for _,v ipairs because I get an error that says i cant do getElementData from a table.

Just to you guys undertand: I'm trying to get all members from a group and give money to all members, but I'm getting problems with this for and tables. How can I outPutChatBox the table to see if I'm getting the right names ?

  
        local turfGang = executeSQLQuery("SELECT GangOwner FROM Turf_System WHERE Turfs=?", "Turf["..tostring(3).."]" )  
        local gangMembers = executeSQLQuery("SELECT member_account FROM gang_members WHERE gang_name=?", turfGang ) 
                 
        --local players = getElementsByType ( "player" ) 
        for _, v in ipairs( gangMembers ) do 
            if getElementData(v, "gang") == turfGang then 
                outputChatBox("sucesso", getRootElement(), 0, 255, 0, false ) 
                                --giveplayermoney... 
            end 
        end 
  

Thanks!

Link to comment

Line 6-7: You're looping a table that's a result from SQL, therefore no value within it is an element, therefore you should not use getElementData on line 7, but rather check the sub-value of v, for example,

v.gang_name --or, 
v['gang_name'] --(same thing) 

Additionally, your second problem is that you're verifying who's from which gang without even querying the information (i.e. your SQL query does not tell you which gang who is from because you only requested to SELECT member_account and nothing else) — which is also quite useless since you've specifically told the SQL query to only retrieve members from a specific gang, so no other records will be returned - therefore, you do not need to check the gang of the record.

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