jkub Posted June 19, 2010 Share Posted June 19, 2010 I have sit for at least an hour and found no good way of making my purchase button work in this new ammunation gui/shop I am working on. Everything that I want to buy is added into a shopping cart ( gridlist ) and I obviously can't loop through the table because it wants a table and guiGridListGetRowCount does not return a table. (Correct if im wrong please, I am trying to learn ) Unless I was to define rows in a gridlist as a custom element type I might be able to loop through them but I have no clue how to do that. Here is a picture so you get the idea of what I am trying to do. I have tried making a table like selectedWeapons = {} then when a weapon is added to the cart I tried inserting those weapons into the table via table.insert which from what I understand is table.insert ( table, position, value ) I tried defining a position and leaving the position out and either way it seemed to overwrite the entire table to the last weapon that I inserted into the table. I used table.maxn to get the end of the table (I did some research and from what I understand it gets the table length) So I tried table.insert ( selectedWeapons, table.maxn(selectedWeapons)+1, weaponID ) that still rewrote the table and gave me one value regardless of how many weapons I had in my shopping cart Link to comment
MaddDogg Posted June 19, 2010 Share Posted June 19, 2010 I just tested table.insert and it just works fine. It is always a good idea to post the respective part of the script, which is not working. So you should post it here, there is probably a mistake in it. Also you should never use a GUI system to store data. It should always only be used to display it and maybe an entry in a gridlist can be marked with a certain value to be able to identify it, but you should never use the gridlist data variables as a kind of table to store your values. I say this, because you talked about a table you needed and that guiGridListGetRowCount does not return a table. Btw, here is my test script I just used, maybe it will help you: client-side: testTable = {} addCommandHandler("tableadd", function (cmdtext, value) if isnumber(value) then table.insert(testTable, tonumber(value)) printTestTable() end end , false) addCommandHandler("tableprint", function () printTestTable() end , false) function printTestTable() outputChatBox("TEST TABLE - PRINT OUT:") for index, value in ipairs(testTable) do outputChatBox(" " .. index .. ": " .. value) end end Link to comment
jkub Posted June 21, 2010 Author Share Posted June 21, 2010 I just tested table.insert and it just works fine.It is always a good idea to post the respective part of the script, which is not working. So you should post it here, there is probably a mistake in it. Also you should never use a GUI system to store data. It should always only be used to display it and maybe an entry in a gridlist can be marked with a certain value to be able to identify it, but you should never use the gridlist data variables as a kind of table to store your values. I say this, because you talked about a table you needed and that guiGridListGetRowCount does not return a table. Btw, here is my test script I just used, maybe it will help you: client-side: testTable = {} addCommandHandler("tableadd", function (cmdtext, value) if isnumber(value) then table.insert(testTable, tonumber(value)) printTestTable() end end , false) addCommandHandler("tableprint", function () printTestTable() end , false) function printTestTable() outputChatBox("TEST TABLE - PRINT OUT:") for index, value in ipairs(testTable) do outputChatBox(" " .. index .. ": " .. value) end end Thank you I just tried out that code and had to correct what seems to be a typo "isnumber"? to tonumber. Anyway thank you very much I'm going to see if I can "weave" this into my shop code to see if it works Ill get back later Link to comment
jkub Posted June 23, 2010 Author Share Posted June 23, 2010 Thanks guys. I have most of my weapon shop going and it seems to be working well. I got the tables in right and it's beautiful. Just need to find a way to write receipts. I'll post some code later. I'm typing from an iPod right now lol 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