Jump to content

[Question] How to destroy elements from a table


kieran

Recommended Posts

Hello, I know how to add, and get elements from a table, but I have made a GUI for a job script, when I click it triggers a function, and I want the clicked image to be destroyed once I click it and the function is triggered, code is below.

Spoiler

--Images

local image_name = {
	{"iron/iron_1.jpg"},
	{"iron/iron_2.jpg"},
	{"iron/iron_3.jpg"},
	{"iron/iron_4.jpg"}
}

local image_loc = {--location on the gui window (is messy, will fix it later)
	{0.1, 0.1},
	{0.8, 0.7},
	{1, 0.1},
	{0, 0.1}
}

image = {}--the table where images are placed into

function destroy_image()
	destroyElement(tostring(image[i][1]))--What am I doing wrong here?
end


--Create the images

function GUI()
	Iron_Window = guiCreateWindow(0.25, 0.25, 0.5, 0.5, "Iron Miner", true) --This is the window
	for i=1,#image_name do --places all the images from table
		local x,y = image_loc[i][1],image_loc[i][2]
		image[i] = guiCreateStaticImage( x, y, 0.25, 0.25, tostring(image_name[i][1]), true, Iron_Window)
		addEventHandler("onClientGUIClick",image[i],destroy_image)--adds handler for each image
	end
end

 

Problem on line 20, debugscript 3 shows: Bad argument @ 'destoyElement' [Expected element at argument 1, got string 'table: 534E2AD0]

So obviously it got the table as a string, but how can I get the clicked image from the table? 

Thanks for the help :) once GUI is neat and working going to put script on community :D

Edited by kieran
typos
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...