Jump to content

guiLabel - clickedElement, get false


Artisz

Recommended Posts

Hi!

 

I want to get the clicked gui label's text, what I clicked on. There is a loop, so I can't add the label an own ID, or I don't know how can I do it.

So I create labels in a loop(with the online players's name), and then under the onClientClick eventhandler, I retrieve the clickedElement type, but I get false. Everywhere I clicked, I get just false

 

slot = 0
for v, character in ipairs(getElementsByType("player")) do
	local characterName = getElementData(character, "CharName")
	local name = tostring(characterName)
    slot = slot + 1                
                                        
	guiCreateLabel(440,230 + slot * (30) ,700,50,name,false)
end

function MemberClick ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement )
    if (button == "left" and state == "up") then
		local tipe = getElementType( clickedElement )
		outputChatBox(tostring(tipe))
	end
end
addEventHandler ( "onClientClick", root, MembeClick)

 

Link to comment

You have a missing 'r' in the function name in the addEventHandler function so ;

 

function MemberClick ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement )
    if ( button == 'left' and state == 'up' and clickedElement ) then
		outputChatBox ( getElementType( clickedElement ) )
	end
end
addEventHandler ( 'onClientClick',root,MemberClick )
 

 

and this should not give you false anymore because you have to make sure that you have clicked an element .

 

Regards,

@Artisz

Edited by FaHaD
Link to comment
aMyLabelOne = guiCreateLabel ( x,y,width,height,'FaHaD',false )
aMyLabelTwo = guiCreateLabel ( x,y,width,height,'Artisz',false )
aMyPositions = { 
	{ x,y,width,height,aMyLabelOne };
	{ x,y,width,height,aMyLabelTwo };
	-- Usage = { x,y,width,height,label }
	-- This how to use this put your label values inside this table
	-- X = Your label x 
	-- Y = Your label y
	-- Width = Your label width 
	-- Height = Your label height
	-- Label = The label verible
	-- And see the results is should out put the labels text
	-- You have to replace the x,y,width,height in the table and labels in here to see the results.
}
function isMouseInPosition ( x,y,width,height )
	if ( not isCursorShowing( ) ) then
		return false
	end
    local sx, sy = guiGetScreenSize ( )
    local cx, cy = getCursorPosition ( )
    local cx, cy = ( cx * sx ), ( cy * sy )
    if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then
        return true
    else
        return false
    end
end

addEventHandler ( 'onClientClick',root,
	function ( button,state )
		if ( button == 'left' and state == 'up' ) then
		for _,aValue in ipairs ( aMyPositions ) do
		if isMouseInPosition ( aValue[1],aValue[2],aValue[3],aValue[4] ) then
					outputChatBox ( guiGetText ( aValue[5] ) )
				end
			end
		end
	end
)

 

@Artisz

PS. This is just an example.

+ Also i forgot to put 'break' so add it to the code.

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...