Jump to content

bad argument #1 to 'unpack'


saluta

Recommended Posts

How to fix this error

addEventHandler("onClientGUIClick", resourceRoot, function()
    if (source == Grid_VS) then
        local carName = guiGridListGetItemText(Grid_VS, guiGridListGetSelectedItem(Grid_VS), 1)
        local carID = getVehicleModelFromNewName(carName) or getVehicleModelFromName(carName)
        local c1, c2, c3, c4 = unpack(vehicleSpeeds[carID])
        guiSetText(cLbl[1], "Stoke. speed: "..c1.." km/h.")
        guiSetText(cLbl[2], "Max. speed: "..c2.." km/h.")
        guiSetText(cLbl[3], "Acceleration 0-100 for "..c3.." s.")
        guiSetText(cLbl[4], "Drive unit: "..c4..".")
    end
end)

 

Link to comment
  • Moderators

 

1 hour ago, saluta said:

How to fix this error

 

You should first check if the table exist. If not, fill in the blanks.


local blankValue = "-"
local c1, c2, c3, c4 = blankValue, blankValue, blankValue, blankValue

local speedData = vehicleSpeeds[carID]
if speedData then
	c1, c2, c3, c4 = unpack(speedData)
end

guiSetText(cLbl[1], "Stoke. speed: "..c1.." km/h.")
guiSetText(cLbl[2], "Max. speed: "..c2.." km/h.")
guiSetText(cLbl[3], "Acceleration 0-100 for "..c3.." s.")
guiSetText(cLbl[4], "Drive unit: "..c4..".")

 

Link to comment
12 hours ago, IIYAMA said:

 

 

You should first check if the table exist. If not, fill in the blanks.



local blankValue = "-"
local c1, c2, c3, c4 = blankValue, blankValue, blankValue, blankValue

local speedData = vehicleSpeeds[carID]
if speedData then
	c1, c2, c3, c4 = unpack(speedData)
end

guiSetText(cLbl[1], "Stoke. speed: "..c1.." km/h.")
guiSetText(cLbl[2], "Max. speed: "..c2.." km/h.")
guiSetText(cLbl[3], "Acceleration 0-100 for "..c3.." s.")
guiSetText(cLbl[4], "Drive unit: "..c4..".")

 

Thank you so much, low bow.

  • Like 1
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...