Hero192 Posted July 25, 2015 Share Posted July 25, 2015 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
Hero192 Posted July 25, 2015 Author Share Posted July 25, 2015 Please anyone can give me a hand on that? i see only GTX who's helpful now .. Link to comment
Hero192 Posted July 25, 2015 Author Share Posted July 25, 2015 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
Perfect Posted July 25, 2015 Share Posted July 25, 2015 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
Hero192 Posted July 25, 2015 Author Share Posted July 25, 2015 Thanks it fixed ,But i have one more problem, its about how to moves/navigate with Arrows in guigridList i tried that but i failed Link to comment
GTX Posted July 25, 2015 Share Posted July 25, 2015 You are ALWAYS bringing up solved problems. I don't know what's wrong with you? viewtopic.php?f=91&t=90522#p813443 Link to comment
Hero192 Posted July 25, 2015 Author Share Posted July 25, 2015 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
GTX Posted July 25, 2015 Share Posted July 25, 2015 bindKey("arrow_d", "down", function() local scrollPos = guiGridListGetVerticalScrollPosition(sevenShopList) guiGridListSetVerticalScrollPosition(sevenShopList, scrollPos+1) end ) Link to comment
Hero192 Posted July 25, 2015 Author Share Posted July 25, 2015 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
GTX Posted July 25, 2015 Share Posted July 25, 2015 It should work, I don't see why not. Remove setTimer ( guiGridListSetVerticalScrollPosition, 50, 1, sevenShopList, 100 ) Link to comment
Hero192 Posted July 25, 2015 Author Share Posted July 25, 2015 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
GTX Posted July 25, 2015 Share Posted July 25, 2015 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
Hero192 Posted July 25, 2015 Author Share Posted July 25, 2015 Still doesn't works any other solide idea? Where's the bind of the key? when i try to bind it ,it says bad argument. Link to comment
GTX Posted July 26, 2015 Share Posted July 26, 2015 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
Hero192 Posted July 26, 2015 Author Share Posted July 26, 2015 Still doesn't workings without any errors Link to comment
GTX Posted July 26, 2015 Share Posted July 26, 2015 "Doesn't work" doesn't help me. I don't know what's wrong, the code seems alright. Link to comment
1B0Y Posted July 26, 2015 Share Posted July 26, 2015 guiGridListGetSelectedItem can return nil if nothing is selected. Create a if statement to check if that function is not returning nil and then load the data from the table. Link to comment
Hero192 Posted July 26, 2015 Author Share Posted July 26, 2015 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
Hero192 Posted July 26, 2015 Author Share Posted July 26, 2015 Anyone??? im stuck on this problem please understand my situation Link to comment
Hero192 Posted July 26, 2015 Author Share Posted July 26, 2015 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
GTX Posted July 26, 2015 Share Posted July 26, 2015 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
Hero192 Posted July 27, 2015 Author Share Posted July 27, 2015 It returns with the same results ,any way? because it's possible im just out of experiences thats why Link to comment
GTX Posted July 27, 2015 Share Posted July 27, 2015 Maybe try guiGridListSetVerticalScrollPosition(sevenShopList, 50) only? I don't know, function might be bugged. Link to comment
Hero192 Posted July 27, 2015 Author Share Posted July 27, 2015 Maybe try guiGridListSetVerticalScrollPosition(sevenShopList, 50) only? I don't know, function might be bugged. The same problem Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now