Jump to content

Table.insert (nil value)


Miika

Recommended Posts

Hi,

I got this type of error in my garage saver script:

ERROR: garagesystem\server.lua:6: attempt to call field 'insert' (a nil value) 

Part of my code:

local vehicle = getPedOccupiedVehicle(hitElement) 
local handlingsTable = {} 
  
for i=1, #handlingtable do 
    local dvalue = getVehicleHandling(vehicle)[handlingtable[i]] 
    table.insert(handlingsTable, dvalue) 
end 
xmlNodeSetAttribute(datanode, "handling", toJSON(handlingsTable)) 

Table:

handlingtable = { 
    "mass", 
    "turnMass", 
    "dragCoeff", 
    "centerOfMass", 
    "percentSubmerged", 
    "tractionMultiplier", 
    "tractionLoss", 
    "tractionBias", 
    "numberOfGears", 
    "maxVelocity", 
    "engineAcceleration", 
    "engineInertia", 
    "driveType", 
    "engineType", 
    "brakeDeceleration", 
    "brakeBias", 
    "ABS", 
    "steeringLock", 
    "suspensionForceLevel", 
    "suspensionDamping", 
    "suspensionHighSpeedDamping", 
    "suspensionUpperLimit", 
    "suspensionLowerLimit", 
    "suspensionFrontRearBias", 
    "suspensionAntiDiveMultiplier", 
    "seatOffsetDistance", 
    "collisionDamageMultiplier", 
    "monetary", 
    "modelFlags", 
    "handlingFlags", 
    "headLight", 
    "tailLight", 
    "animGroup" 
} 

Link to comment

it's handlingsTable not handlingtable.

if it doesn't work try to use sth like this

if ( not handlingsTable[vehicle] ) then 
        handlingsTable[vehicle] = {} 
    end 
     
handlingsTable[vehicle] = {--[[ put your value here]]} 

Link to comment

It's not good to put elements into XML file.

handlingtable must be in same script as your 'for' loop.

local vehicle = getPedOccupiedVehicle(hitElement) 
local handlingsTable = {} 
  
handlingtable = { 
    "mass", 
    "turnMass", 
    "dragCoeff", 
    "centerOfMass", 
    "percentSubmerged", 
    "tractionMultiplier", 
    "tractionLoss", 
    "tractionBias", 
    "numberOfGears", 
    "maxVelocity", 
    "engineAcceleration", 
    "engineInertia", 
    "driveType", 
    "engineType", 
    "brakeDeceleration", 
    "brakeBias", 
    "ABS", 
    "steeringLock", 
    "suspensionForceLevel", 
    "suspensionDamping", 
    "suspensionHighSpeedDamping", 
    "suspensionUpperLimit", 
    "suspensionLowerLimit", 
    "suspensionFrontRearBias", 
    "suspensionAntiDiveMultiplier", 
    "seatOffsetDistance", 
    "collisionDamageMultiplier", 
    "monetary", 
    "modelFlags", 
    "handlingFlags", 
    "headLight", 
    "tailLight", 
    "animGroup" 
} 
  
for i=1, #handlingtable do 
    local dvalue = getVehicleHandling(vehicle)[handlingtable[i]] 
    table.insert(handlingsTable, dvalue) 
end 
xmlNodeSetAttribute(datanode, "handling", toJSON(handlingsTable)) 

And hitElement should be defined. And datanode also.

Link to comment
it's handlingsTable not handlingtable.

if it doesn't work try to use sth like this

if ( not handlingsTable[vehicle] ) then 
        handlingsTable[vehicle] = {} 
    end 
     
handlingsTable[vehicle] = {--[[ put your value here]]} 

Still not working.

Link to comment
  
local vehicle = getPedOccupiedVehicle(hitElement) 
local handlingsTable = {} 
  
for i,v in ipairs( handlingtable ) do 
    local dvalue = getVehicleHandling(vehicle)[v] 
    table.insert(handlingsTable, dvalue) 
end 
xmlNodeSetAttribute(datanode, "handling", toJSON(handlingsTable)) 
  

Link to comment
  
local vehicle = getPedOccupiedVehicle(hitElement) 
local handlingsTable = {} 
  
for i,v in ipairs( handlingtable ) do 
    local dvalue = getVehicleHandling(vehicle)[v] 
    table.insert(handlingsTable, dvalue) 
end 
xmlNodeSetAttribute(datanode, "handling", toJSON(handlingsTable)) 
  

Same error

Link to comment
  
  
local vehicle = getPedOccupiedVehicle(hitElement) 
local handlingsTable = {} 
  
for i,v in ipairs( handlingtable ) do 
    local dvalue = getVehicleHandling(vehicle)[v] 
    handlingsTable[#handlingsTable+1] = dvalue 
end 
xmlNodeSetAttribute(datanode, "handling", toJSON(handlingsTable)) 
  
  

Link to comment
  
  
local vehicle = getPedOccupiedVehicle(hitElement) 
local handlingsTable = {} 
  
for i,v in ipairs( handlingtable ) do 
    local dvalue = getVehicleHandling(vehicle)[v] 
    handlingsTable[#handlingsTable+1] = dvalue 
end 
xmlNodeSetAttribute(datanode, "handling", toJSON(handlingsTable)) 
  
  

Oh, this worked perfectly! Thank you and @GTX (used your method wrong first)

Link to comment
  
  
local vehicle = getPedOccupiedVehicle(hitElement) 
local handlingsTable = {} 
  
for i,v in ipairs( handlingtable ) do 
    local dvalue = getVehicleHandling(vehicle)[v] 
    handlingsTable[#handlingsTable+1] = dvalue 
end 
xmlNodeSetAttribute(datanode, "handling", toJSON(handlingsTable)) 
  
  

Oh, this worked perfectly! Thank you and @GTX (used your method wrong first)

Uhmm welcome

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