Jump to content

[HELP] The event handler runs twice (dgs element)


p1kas

Recommended Posts

There is a button in the form of a rectangle:

local buttonAuth_round = dgs:dgsCreateRoundRect(30,false,tocolor(62,153,247))
local buttonAuth = dgs:dgsCreateImage(182,0,164,56,buttonAuth_round,false,loginButtons,tocolor(62,153,247))
local buttonAuth_text = dgs:dgsCreateLabel(57,18,50,20,'Войти', false, buttonAuth)

There is an event handler:

addEventHandler("onDgsMouseClick", buttonAuth, function()
	local login, password = dgs:dgsGetText(inputLogin_edit), dgs:dgsGetText(inputPass_edit)
	if not string.find(login, "%S") then return end
	if not string.find(password, "%S") then return end
	triggerServerEvent("playerLogin", getLocalPlayer(), login, password)
end, false)

But when you click on a button or any other dgs element (which is being processed) - it is triggered two times (simultaneously), how can this be fixed?

Link to comment
  • Moderators
12 hours ago, p1kas said:

But when you click on a button or any other dgs element (which is being processed) - it is triggered two times (simultaneously), how can this be fixed?

Afaik there is a Mouse up and down state. The second argument.

Edited by IIYAMA
Link to comment
addEventHandler("onDgsMouseClick", buttonAuth, function(btn, state)
	if btn == "left" and state == "down" then
		local login, password = dgs:dgsGetText(inputLogin_edit), dgs:dgsGetText(inputPass_edit)
		if not string.find(login, "%S") then return end
		if not string.find(password, "%S") then return end
		triggerServerEvent("playerLogin", getLocalPlayer(), login, password)
	end
end, false)

This should fix the double execution.

Edited by SpecT
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...