Jump to content

I have problem


Hero192

Recommended Posts

Hey there,

I am trying to add "$" in the gridlist with numbers as money,It sends me errors when i click on the first ID,i mean the first row other IDs working fine,but the first ID always gives this Error

ERROR: attempt to index field '?' (a nil value)

it says the error is in this line

      local weapPrice = Weapons[guiGridListGetSelectedItem (grid)][3] 

--Table of weapons:

Weapons = { 
{1,1,400}, --First ID always gives errors 
{2,2,1500}, 
{5,5,550}, 
{6,6,700}, 
{7,7,850}, 
{8,8,1500}, 
{9,9,2000}, 
{10,10,800}, 
{12,12,800}, 
{15,15,500} 
} 

Link to comment

Please GTX,Help me also to fix the row moves with Arrows i stuck here plus the first ID doesn't works when i add

        guiGridListSetItemText (sevenShopList, row, 3, v[3].."$" , false, false) 

others working fine exept the first ID,you can read the error

window = guiCreateWindow(519*x,214*y,347*x,282*y,"24/7 Shop",false) 
sevenShopList = guiCreateGridList(11*x,25*y,326*x,218*y,false,window) 
guiGridListSetSelectionMode(sevenShopList,0) 
guiGridListAddColumn(sevenShopList,"ID:",0.19,window) 
guiGridListAddColumn(sevenShopList,"Name:",0.48,window) 
guiGridListAddColumn(sevenShopList,"Price",0.18,window) 
buy = guiCreateButton(13*x,249*y,134*x,23*y,"Buy",false,window) 
reject = guiCreateButton(199*x,249*y,134*x,23*y,"Close ",false,window) 
guiWindowSetSizable(window,false) 
guiSetVisible (window,false) 
 local client = getLocalPlayer() 
Weapons = { 
{1,1,400}, 
{2,2,1500}, 
{5,5,550}, 
{6,6,700}, 
{7,7,850}, 
{8,8,1500}, 
{9,9,2000}, 
{10,10,800}, 
{12,12,800}, 
{15,15,500} 
} 
  
  
function DD() 
for k,v in ipairs (Weapons) do 
local row = guiGridListAddRow(sevenShopList) 
        guiGridListSetItemText(sevenShopList, row, 1,v[1], false, false) 
        guiGridListSetItemText(sevenShopList, row, 2, getWeaponNameFromID(v[2]), false, false) 
        guiGridListSetItemText (sevenShopList, row, 3, v[3].."$" , false, false) 
    end 
end 
  
function weaponGUI(Weapons) 
guiGridListClear(sevenShopList) 
 DD() 
    guiSetVisible(window, true) 
    showCursor(true) 
  
end 
addEvent("sevenShopshowGUI",true) 
addEventHandler("sevenShopshowGUI",root,weaponGUI) 
  
addEventHandler("onClientGUIClick",root, 
function () 
   if (source == reject) then 
        guiSetVisible(window, false) 
        showCursor(false) 
          -- unbindKey("arrow_up", "down",arr ) 
   -- unbindKey("arrow_down", "down",arl ) 
    elseif (source == buy) then 
    if (guiGridListGetSelectedItem (sevenShopList)) then 
    local weapID = guiGridListGetItemText ( sevenShopList, guiGridListGetSelectedItem (sevenShopList), 1 ) 
    local weapName = guiGridListGetItemText ( sevenShopList, guiGridListGetSelectedItem (sevenShopList), 2 ) 
      local weapPrice = Weapons[guiGridListGetSelectedItem (sevenShopList)][3] 
     local row = guiGridListAddRow ( sevenShopList ) 
    guiGridListSetItemText ( sevenShopList, row, column, message, false, false ) 
    local rowCount = guiGridListGetRowCount ( sevenShopList ) 
    setTimer ( guiGridListSetVerticalScrollPosition, 50, 1, sevenShopList, 100 ) 
    guiSetVisible(window, false) 
    showCursor(false) 
    triggerServerEvent("weapon_Name",getLocalPlayer(),weapID,weapName,weapPrice) 
      end 
   end 
end) 
  
  
 bindKey("arrow_down", "down", 
    function() 
        local scrollPos = guiGridListGetVerticalScrollPosition(sevenShopList) 
        guiGridListSetVerticalScrollPosition(sevenShopList, scrollPos+1) 
    end 
) 

Link to comment

That's because you are trying concatenate number with a string.

In which case you should do this:

guiGridListSetItemText (sevenShopList, row, 3, tostring(v[3]).."$" , false, false) 

And for your another problem.

Try replacing

local weapPrice = Weapons[guiGridListGetSelectedItem (grid)][3] 

with

local weapPrice = Weapons[guiGridListGetSelectedItem (grid) + 1][3] 

Link to comment

Yes i knows,i tried your example but i failed thats why i put the code again,to correct me

-It dosn't works thats why.

window = guiCreateWindow(519*x,214*y,347*x,282*y,"24/7 Shop",false) 
sevenShopList = guiCreateGridList(11*x,25*y,326*x,218*y,false,window) 
guiGridListSetSelectionMode(sevenShopList,0) 
guiGridListAddColumn(sevenShopList,"ID:",0.19,window) 
guiGridListAddColumn(sevenShopList,"Name:",0.48,window) 
guiGridListAddColumn(sevenShopList,"Price",0.18,window) 
buy = guiCreateButton(13*x,249*y,134*x,23*y,"Buy",false,window) 
reject = guiCreateButton(199*x,249*y,134*x,23*y,"Close ",false,window) 
guiWindowSetSizable(window,false) 
guiSetVisible (window,false) 
 local client = getLocalPlayer() 
Weapons = { 
{1,1,400}, 
{2,2,1500}, 
{5,5,550}, 
{6,6,700}, 
{7,7,850}, 
{8,8,1500}, 
{9,9,2000}, 
{10,10,800}, 
{12,12,800}, 
{15,15,500} 
} 
  
  
function DD() 
for k,v in ipairs (Weapons) do 
local row = guiGridListAddRow(sevenShopList) 
        guiGridListSetItemText(sevenShopList, row, 1,v[1], false, false) 
        guiGridListSetItemText(sevenShopList, row, 2, getWeaponNameFromID(v[2]), false, false) 
        guiGridListSetItemText (sevenShopList, row, 3, v[3].."$" , false, false) 
    end 
end 
  
function weaponGUI(Weapons) 
guiGridListClear(sevenShopList) 
 DD() 
    guiSetVisible(window, true) 
    showCursor(true) 
  
end 
addEvent("sevenShopshowGUI",true) 
addEventHandler("sevenShopshowGUI",root,weaponGUI) 
  
addEventHandler("onClientGUIClick",root, 
function () 
   if (source == reject) then 
        guiSetVisible(window, false) 
        showCursor(false) 
          -- unbindKey("arrow_up", "down",arr ) 
   -- unbindKey("arrow_down", "down",arl ) 
    elseif (source == buy) then 
    if (guiGridListGetSelectedItem (sevenShopList)) then 
    local weapID = guiGridListGetItemText ( sevenShopList, guiGridListGetSelectedItem (sevenShopList), 1 ) 
    local weapName = guiGridListGetItemText ( sevenShopList, guiGridListGetSelectedItem (sevenShopList), 2 ) 
      local weapPrice = Weapons[guiGridListGetSelectedItem (sevenShopList)][3] 
     local row = guiGridListAddRow ( sevenShopList ) 
    guiGridListSetItemText ( sevenShopList, row, column, message, false, false ) 
    local rowCount = guiGridListGetRowCount ( sevenShopList ) 
    setTimer ( guiGridListSetVerticalScrollPosition, 50, 1, sevenShopList, 100 ) 
    guiSetVisible(window, false) 
    showCursor(false) 
    triggerServerEvent("weapon_Name",getLocalPlayer(),weapID,weapName,weapPrice) 
      end 
   end 
end) 
  
  
 bindKey("arrow_down", "down", 
    function() 
        local scrollPos = guiGridListGetVerticalScrollPosition(sevenShopList) 
        guiGridListSetVerticalScrollPosition(sevenShopList, scrollPos+1) 
    end 
) 

Link to comment
bindKey("arrow_d", "down", 
    function() 
        local scrollPos = guiGridListGetVerticalScrollPosition(sevenShopList) 
        guiGridListSetVerticalScrollPosition(sevenShopList, scrollPos+1) 
    end 
) 

Link to comment
bindKey("arrow_d", "down", 
    function() 
        local scrollPos = guiGridListGetVerticalScrollPosition(sevenShopList) 
        guiGridListSetVerticalScrollPosition(sevenShopList, scrollPos+1) 
    end 
) 

Should i put what you sent me alone without adding that?

   local row = guiGridListAddRow ( sevenShopList ) 
    guiGridListSetItemText ( sevenShopList, row, column, message, false, false ) 
  local rowCount = guiGridListGetRowCount ( sevenShopList ) 
   setTimer ( guiGridListSetVerticalScrollPosition, 50, 1, sevenShopList, 100 ) 

Because it still doesn't works anymore without Errors

Link to comment
It should work, I don't see why not. Remove
setTimer ( guiGridListSetVerticalScrollPosition, 50, 1, sevenShopList, 100 ) 

Still doesn't works,look i added what i did

addEventHandler("onClientGUIClick",root, 
function () 
   if (source == reject) then 
        guiSetVisible(window, false) 
        showCursor(false) 
         unbindKey("arrow_d", "down",arr ) 
    elseif (source == buy) then 
    if (guiGridListGetSelectedItem (sevenShopList)) then 
    local weapID = guiGridListGetItemText ( sevenShopList, guiGridListGetSelectedItem (sevenShopList) , 1 ) 
    local weapName = guiGridListGetItemText ( sevenShopList, guiGridListGetSelectedItem (sevenShopList) , 2 ) 
      local weapPrice = Weapons[guiGridListGetSelectedItem (sevenShopList)+1][3] 
     local row = guiGridListAddRow ( sevenShopList ) 
    guiGridListSetItemText ( sevenShopList, row, column, message, false, false ) 
       local rowCount = guiGridListGetRowCount ( sevenShopList ) 
  setTimer ( guiGridListSetVerticalScrollPosition, 50, 1, sevenShopList, 100 ) 
    guiSetVisible(window, false) 
    showCursor(false) 
    triggerServerEvent("weapon_Name",getLocalPlayer(),weapID,weapName,weapPrice) 
      end 
   end 
end) 
      
bindKey("arrow_d", "down", 
    function arr() 
        local scrollPos = guiGridListGetVerticalScrollPosition(sevenShopList) 
        guiGridListSetVerticalScrollPosition(sevenShopList, scrollPos+1) 
    end 
) 
  

Link to comment

Wrong.

addEventHandler("onClientGUIClick",root, 
function () 
   if (source == reject) then 
        guiSetVisible(window, false) 
        showCursor(false) 
         unbindKey("arrow_d", "down",arr ) 
    elseif (source == buy) then 
    if (guiGridListGetSelectedItem (sevenShopList)) then 
    local weapID = guiGridListGetItemText ( sevenShopList, guiGridListGetSelectedItem (sevenShopList) , 1 ) 
    local weapName = guiGridListGetItemText ( sevenShopList, guiGridListGetSelectedItem (sevenShopList) , 2 ) 
      local weapPrice = Weapons[guiGridListGetSelectedItem (sevenShopList)+1][3] 
     local row = guiGridListAddRow ( sevenShopList ) 
    guiGridListSetItemText ( sevenShopList, row, column, message, false, false ) 
       local rowCount = guiGridListGetRowCount ( sevenShopList ) 
  setTimer ( guiGridListSetVerticalScrollPosition, 50, 1, sevenShopList, 100 ) 
    guiSetVisible(window, false) 
    showCursor(false) 
    triggerServerEvent("weapon_Name",getLocalPlayer(),weapID,weapName,weapPrice) 
      end 
   end 
end) 
     
    function arr() 
        local scrollPos = guiGridListGetVerticalScrollPosition(sevenShopList) 
        guiGridListSetVerticalScrollPosition(sevenShopList, scrollPos+1) 
    end 

Link to comment
addEventHandler("onClientGUIClick",root, 
function () 
   if (source == reject) then 
        guiSetVisible(window, false) 
        showCursor(false) 
    elseif (source == buy) then 
    if (guiGridListGetSelectedItem (sevenShopList)) then 
    local weapID = guiGridListGetItemText ( sevenShopList, guiGridListGetSelectedItem (sevenShopList) , 1 ) 
    local weapName = guiGridListGetItemText ( sevenShopList, guiGridListGetSelectedItem (sevenShopList) , 2 ) 
      local weapPrice = Weapons[guiGridListGetSelectedItem (sevenShopList)+1][3] 
     local row = guiGridListAddRow ( sevenShopList ) 
    guiGridListSetItemText ( sevenShopList, row, column, message, false, false ) 
       local rowCount = guiGridListGetRowCount ( sevenShopList ) 
    guiSetVisible(window, false) 
    showCursor(false) 
    triggerServerEvent("weapon_Name",getLocalPlayer(),weapID,weapName,weapPrice) 
      end 
   end 
end) 
    
    function arr() 
        local scrollPos = guiGridListGetVerticalScrollPosition(sevenShopList) 
        guiGridListSetVerticalScrollPosition(sevenShopList, scrollPos+1) 
    end 
    bindKey("arrow_d", "down", arr) 
  
    function arr2() 
        local scrollPos = guiGridListGetVerticalScrollPosition(sevenShopList) 
        guiGridListSetVerticalScrollPosition(sevenShopList, scrollPos-1) 
    end 
    bindKey("arrow_u", "down", arr2) 

Link to comment

I tried to debug the code, When i use the arrows it returns, with

INFO: execute: function arr()

INFO:scrollPos: -0

Any idea please?

    function arr(key) 
    outputDebugString("execute: function arr()") -- debug 
    if isElement(sevenShopList) then 
        local scrollPos = guiGridListGetVerticalScrollPosition(sevenShopList) 
        outputDebugString("scrollPos: " .. tostring(scrollPos)) -- debug 
        if key == "arrow_d" then 
            guiGridListSetVerticalScrollPosition(sevenShopList, scrollPos+1) 
        else 
            guiGridListSetVerticalScrollPosition(sevenShopList, scrollPos-1) 
        end 
    else 
        outputDebugString("sevenShopList isn't an element.") -- debug 
    end 
end 
bindKey("arrow_d", "down", arr) 
bindKey("arrow_u", "down", arr) 

Link to comment
I tried to debug the code, When i use the arrows it returns, with

INFO: execute: function arr()

INFO:scrollPos: -0

Any idea please?

    function arr(key) 
    outputDebugString("execute: function arr()") -- debug 
    if isElement(sevenShopList) then 
        local scrollPos = guiGridListGetVerticalScrollPosition(sevenShopList) 
        outputDebugString("scrollPos: " .. tostring(scrollPos)) -- debug 
        if key == "arrow_d" then 
            guiGridListSetVerticalScrollPosition(sevenShopList, scrollPos+1) 
        else 
            guiGridListSetVerticalScrollPosition(sevenShopList, scrollPos-1) 
        end 
    else 
        outputDebugString("sevenShopList isn't an element.") -- debug 
    end 
end 
bindKey("arrow_d", "down", arr) 
bindKey("arrow_u", "down", arr) 

Anyone can give me a hand on that?

Link to comment

Hmm, function might be bugged then if that doesn't work. Try this:

function arr(key) 
    outputDebugString("execute: function arr()") -- debug 
    if isElement(sevenShopList) then 
        local scrollPos = guiGridListGetVerticalScrollPosition(sevenShopList) 
        outputDebugString("scrollPos: " .. tostring(scrollPos)) -- debug 
        if key == "arrow_d" then 
            guiGridListSetVerticalScrollPosition(sevenShopList, scrollPos-50) 
        else 
            guiGridListSetVerticalScrollPosition(sevenShopList, scrollPos+50) 
        end 
    else 
        outputDebugString("sevenShopList isn't an element.") -- debug 
    end 
end 
bindKey("arrow_d", "down", arr) 
bindKey("arrow_u", "down", arr) 

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