Jump to content

table index is nil


dragonofdark

Recommended Posts

Hello,

I made a tolls system there are some months ago and I would like to modify it to use mySQL for more facility.

Here is my problem, I have a "table index is nil" error when I start the resource and it loads only one barrier (with ID 1)

My script :

  
local peageIDs = { } 
local peages = { } 
  
addEventHandler( "onResourceStart", resourceRoot, 
    function( ) 
        -- Create the SQL tables if not already. 
        if not exports.sql:create_table( 'peages',  
            { 
                { name = 'peageID', type = 'int(10) unsigned', primary_key = true }, 
                { name = 'barrierModel', type = 'int(10) unsigned' }, 
                { name = 'interior', type = 'tinyint(3) unsigned', default = 0 }, 
                { name = 'dimension', type = 'int(10) unsigned', default = 0 }, 
                -- 
                { name = 'markerposX', type = 'float' }, 
                { name = 'markerposY', type = 'float' }, 
                { name = 'markerposZ', type = 'float' }, 
                -- 
                { name = 'posX', type = 'float' }, 
                { name = 'posY', type = 'float' }, 
                { name = 'posZ', type = 'float' }, 
                { name = 'rotX', type = 'float' }, 
                { name = 'rotY', type = 'float' }, 
                { name = 'rotZ', type = 'float' }, 
                -- 
                { name = 'openPosX', type = 'float' }, 
                { name = 'openPosY', type = 'float' }, 
                { name = 'openPosZ', type = 'float' }, 
                { name = 'openRotX', type = 'float' }, 
                { name = 'openRotY', type = 'float' }, 
                { name = 'openRotZ', type = 'float' }, 
                -- 
                { name = 'prix', type = 'int(10) unsigned', default = 0 }, -- price of the taxe when passing the toll 
            } ) then cancelEvent( ) return end 
         
        -- load the tolls 
        local result = exports.sql:query_assoc( "SELECT * FROM peages ORDER BY peageID ASC" ) 
        if result then 
            for key, data in ipairs( result ) do 
                local barrier = createObject ( data.barrierModel, data.posX, data.posY, data.posZ, data.rotX, data.rotY, data.rotZ ) 
                local marker = createMarker( data.markerposX, data.markerposY, data.markerposZ, 'cylinder', 3, 100, 100, 100, 100 ) 
                 
                -- tables for ID -> data 
                peageIDs[ data.peageID ] = peage 
                peages[ peage ] = { peageID = data.peageID, interior = data.interior, dimension = data.dimension } 
            end 
        end 
    end 
) 
  

Debugscript : ERROR: peages\peage.lua:44: table index is nil

Thanks

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