Jump to content

[HELP] Unpack bad argument


Recommended Posts

With this script I plan to have it unpack the data (startx, starty, etc.) from the grildist data. But I keep getting the error of Bad Argument: expected Table got nil. I am not sure why this is happening because I do have it as a table in the gridlist as a table. Please help in anyway you can. Thanks in advance.

function loadHandler(button, state) 
    if button == "left" and state == "up" then 
        local row, col = guiGridListGetSelectedItem(glistLoadList) 
        local data = guiGridListGetItemData(glistLoadList, row, col) 
        if row and col and row ~= -1 and col ~=-1 then 
            local startx, starty, startz, endx, endy, endz, cash = unpack(data) 
            triggerEvent("startLoad", localPlayer, startx, starty, startz, endx, endy, endz, cash) 
        end 
    end 
end 
  
function beginLoad(startx, starty, startz, endx, endy, endz, cash) 
    createMarker(startx, starty, startz, "checkpoint", 5) 
    createBlip(-102, -70, 5, 0, 2, 0, 0, 255) 
end 
addEvent("startLoad", false) 
addEventHandler("startLoad", localPlayer, beginLoad) 

Link to comment

Its the same code you helped me with last time. Sorry I left that out.

function fillLoadList() 
    local file = xmlLoadFile("loads.xml") 
    if (file) then 
        local childs = xmlNodeGetChildren(file) 
        local randomChilds = {} 
        for index = 1, 3 do 
            table.insert(randomChilds, childs[math.random(#childs)]) 
        end 
        for _, loads in ipairs (randomChilds) do 
            local row = guiGridListAddRow(glistLoadList) 
            local attrs = xmlNodeGetAttributes(loads) 
            local startx = attrs.startx 
            local starty = attrs.starty 
            local startz = attrs.startz 
            local endx = attrs.endx 
            local endy = attrs.endy 
            local endz = attrs.endz 
            local cash = attrs.cash 
            guiGridListSetItemText(glistLoadList, row, 1, attrs.cargo, false, false) 
            guiGridListSetItemText(glistLoadList, row, 2, attrs.pickup, false, false) 
            guiGridListSetItemData(glistLoadList, row, 2, {attrs.startx, attrs.starty, attrs.startz}) 
            guiGridListSetItemText(glistLoadList, row, 3, attrs.dropoff, false, false) 
            guiGridListSetItemData(glistLoadList, row, 3, {attrs.endx, attrs.endy, attrs.endz}) 
            guiGridListSetItemText(glistLoadList, row, 4, attrs.pay, false, false) 
            guiGridListSetItemData(glistLoadList, row, 4, attrs.cash) 
        end 
        xmlUnloadFile(file) 
    end 
end 

Link to comment
function loadHandler(button, state) 
    if button == "left" and state == "up" then 
        local row, col = guiGridListGetSelectedItem(glistLoadList) 
        if ( row and col and row ~= -1 and col ~=-1 ) then 
            local data = guiGridListGetItemData(glistLoadList, row, 2) 
            local startx, starty, startz, endx, endy, endz, cash = unpack(data) 
            triggerEvent("startLoad", localPlayer, startx, starty, startz, endx, endy, endz, cash) 
        end 
    end 
end 
  
function beginLoad(startx, starty, startz, endx, endy, endz, cash) 
    createMarker(startx, starty, startz, "checkpoint", 5) 
    createBlip(-102, -70, 5, 0, 2, 0, 0, 255) 
end 
addEvent("startLoad", false) 
addEventHandler("startLoad", localPlayer, beginLoad) 

Try it.

Link to comment

Yeah I noticed that. I was thinking about it but I didn't want to totally screw my whole mode up. Thanks again. Oh and one question. How can I have a guiElement stay on the screen for 30 seconds? I got the timer but currently it is just delay. I want it to come up and stay for 30 seconds then be gone. Thanks.

Link to comment
  • Moderators
  
function changeVis() 
local state = guiGetVisible(yourGUIName) 
guiSetVisible(yourGUIName,not state) 
end 
setTimer(changeVis,30000,0) 
  

Hahaha, it will just make his gui blicking every 30 secs. He wanted it to be hidden:

function hideMyGui() 
    guiSetVisible(myGuiElement, false) 
end 

And put this line where the gui is shown:

setTimer(hideMyGui, 30*1000, 1) 

The "All-In-One" versiobn to be placed where the gui is shown:

setTimer(function () 
    guiSetVisible(myGuiElement, false) 
end, 30*1000, 1) 

It's using what we called an anonymous function. They are usefull when you know you will never call that function somewhere else in your script.

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