Slimwaffle Posted July 16, 2018 Share Posted July 16, 2018 I am having trouble with some code and could use some help. I want to say table index = to choice box selected. mitem.icount is the table and GameMenu.materials is the choice box. This was the code I used but it keep showing a nil value. mitem.icount = GameMenu.materials:GetSelectedItem() Its for a trash materials button. I want to be able to say table index is = to table index -1 then return the value. Quote Link to comment Share on other sites More sharing options...
macklebee Posted July 16, 2018 Share Posted July 16, 2018 Not sure if i follow exactly what you are asking for, but here is a simple example of a listbox and a button. When the button is pressed, it will delete the selected item from the table used to create the items in the listbox. local window = Window:Create("example",0,0,400,300,Window.Titlebar+Window.Center) local context = Context:Create(window) local gui = GUI:Create(context) local base = gui:GetBase() base:SetScript("Scripts/GUI/Panel.lua") mitem ={} table.insert(mitem,"Wood") table.insert(mitem,"Steel") table.insert(mitem,"Concrete") table.insert(mitem,"Rubber") table.sort(mitem) button1 = Widget:Button("Delete",240,20,100,40,base) listbox1 = Widget:ListBox(20,20,200,100,base) function AddStuffToList(mytable,widget) widget:ClearItems() System:Print(#mytable) if #mytable > 0 then for n = 1, #mytable do widget:AddItem(mitem[n], n==1) end end widget:Redraw() end AddStuffToList(mitem,listbox1) while not window:KeyHit(Key.Escape) do if window:Closed() then return false end while EventQueue:Peek() do local event = EventQueue:Wait() if event.source == button1 then if listbox1:GetSelectedItem()~=-1 then table.remove(mitem,listbox1:GetSelectedItem()+1) AddStuffToList(mitem,listbox1) end end end context:Sync() end Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Slimwaffle Posted July 16, 2018 Author Share Posted July 16, 2018 I figured this out it was actually easier then I thought. Now my issue is getting the choice box to redraw the text. Using the redraw command is not working and using SetText doesn't work either. But here is the code I used to fix it. i = GameMenu.materials:GetSelectedItem() mitem.icount = mitem.icount -1 System:Print(mitem) System:Print(mitem.icount) Quote Link to comment Share on other sites More sharing options...
Slimwaffle Posted July 16, 2018 Author Share Posted July 16, 2018 I am trying to design my inventory so everything is shown on the choice box Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.