Jump to content

Table Index


Slimwaffle
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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

deleteitem.jpg.bd5e854e404d7ca3c0bb9c1cdf6cce82.jpg

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

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)

Trash Button.jpg

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...