kieran Posted November 3, 2017 Share Posted November 3, 2017 (edited) 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 Edited November 3, 2017 by kieran typos Link to comment
quindo Posted November 3, 2017 Share Posted November 3, 2017 What are you even trying to do here: destroyElement(tostring(image[i][1]))--What am I doing wrong here? the tostring doesn't make sense in this place, also why are you trying to access index 1 of the image? just add destroyElement(source) at the end of your MineIronGUI function 1 Link to comment
kieran Posted November 3, 2017 Author Share Posted November 3, 2017 thanks @quindo, was thinking it would get the button instead of the image haha, makes sense now, if you want to get the button, you gotta declare it if you want to get the element, get the source. 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