.friendly Posted May 8, 2018 Posted May 8, 2018 I have a problem with lua tables. I don't understand how I can get info from tables. For example. I have a db with zones and when resource starting I put all info in lua table turfElement = {} function onGangzonesLoad() dbQuery( function(qh) local result = dbPoll(qh, -1) if result then for idZone,v in ipairs(result) do local turfCol = createColRectangle(v['gX'], v['gY'], v['gSizeX'], v['gSizeY']) local turfArea = createRadarArea(v['gX'], v['gY'], v['gtSizeX'], v['gtSizeY'], v['r'], v['g'], v['b'], 90) turfElement[idZone] = {turfCol, turfArea, idZone} end end end , db, "SELECT * FROM gangzones") end addEventHandler("onResourceStart", resourceRoot, onGangzonesLoad) But when I want to get info, I have error for idZone,v in pairs(turfElement) do outputChatBox("" .. v.turfArea["gX"] .. "", player, 255, 255, 255) end attempt to index field 'turfArea' <a nil value> What's wrong?
Moderators IIYAMA Posted May 8, 2018 Moderators Posted May 8, 2018 v.turfArea Is nil. Normally you would inspect your table structure first: iprint(turfElement) Save everything first. turfElement[idZone] = {turfCol = turfCol, turfArea = turfArea, idZone = idZone, gX = v.gX, gY = v.gY, gtSizeX = v.gtSizeX, gtSizeY = v.gtSizeY } Then this might work. for idZone,v in pairs(turfElement) do outputChatBox("" .. v.gX .. "", player, 255, 255, 255) end 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now