Jump to content

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


p1kas

Recommended Posts

Posted

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?

Posted (edited)

I believe you need to check the source manually.

like if source == buttonAuth then your function

Take a look at onDgsMouseClick event in the wiki

edit: nevermind im wrong

Edited by Spakye
  • Moderators
Posted (edited)
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

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
On 15/08/2020 at 12:27, IIYAMA said:

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

thank you. can you help me with this pls, i'll grateful for you

 

Posted (edited)
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
  • Moderators
Posted (edited)

If you are lazy to do that, just use onDgsMouseClickDown instead of onDgsMouseClick

Edited by thisdp

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