Jump to content

Table.insert (nil value)


Miika

Recommended Posts

Posted

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" 
} 

Real motorbike backflip / frontflip script: https://forum.mtasa.com/viewtopic.php?f=108&t=98191

Posted

Weird. Maybe you're overriding table function?

Try using

handlingsTable[#handlingsTable+1] = dvalue 

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

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]]} 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

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.

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted
  
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)) 
  

Posted
  
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

Real motorbike backflip / frontflip script: https://forum.mtasa.com/viewtopic.php?f=108&t=98191

Posted
  
  
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)) 
  
  

Posted
  
  
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)

Real motorbike backflip / frontflip script: https://forum.mtasa.com/viewtopic.php?f=108&t=98191

Posted
  
  
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

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