Jump to content

need help at InputBox-Script


Recommended Posts

Dear friends,

I have scripted a InputBox for my own admin panel and in the function are different parameters and one parameter is also a function. This function is called if I press the "OK-Button" at the InputBox. But the next time I create a InputBox, the old event from the OK-Button should be removed. I think I have scripted all true, but everytime I press OK-Button the event is called as many times as I opened the InputBox. I hope anyone of you find the error in the following code:

function showInputBox(title,label,eingabet,abbrechen,func)
removeEventHandler("onClientGUIClick", abbrechenbutton,
function()
guiSetVisible(eingabewindow,false)
guiSetInputEnabled(oldinput)
showCursor(oldcursor)
guiSetEnabled(adminpanel,adminenabled)
end
)
removeEventHandler("onClientGUIClick", eingabebutton,
function()
		oldfunc()
end
)
 
oldinput = guiGetInputEnabled()
oldcursor = isCursorShowing()
guiSetText(eingabewindow, tostring(title))
guiSetText(eingabegrundlabel, tostring(label))
guiSetText(eingabebutton, tostring(eingabet))
guiSetText(abbrechenbutton, tostring(abbrechen))
guiSetInputEnabled(true)
showCursor(true)
guiSetVisible(eingabewindow,true)
guiBringToFront(eingabewindow)
 
function oldfunc()
	func()
end
 
addEventHandler ("onClientGUIClick",abbrechenbutton,
function()
guiSetVisible(eingabewindow,false)
guiSetInputEnabled(oldinput)
showCursor(oldcursor)
guiSetEnabled(adminpanel,adminenabled)
end
,false)
addEventHandler("onClientGUIClick",eingabebutton,
function()
guiSetVisible(eingabewindow,false)
guiSetInputEnabled(oldinput)
showCursor(oldcursor)
		oldfunc()
guiSetEnabled(adminpanel,adminenabled)
end
,false)	
end

Link to comment

You can't remove anonymous functions. If you want to remove functions from event you have to create a function outside other functions. The function has to have a name and be created only once. In your case, you create new anonymous function every time you call showInputBox function and when you addEventHandler this will add another function to the list of functions the event should call and you'll end up with code being executed multiple times.

Make these functions outside showInputBox and let them have their names which you'll than use in addEventHandler and removeEventHandler, otherwise you keep adding new functions and are not removing any functions at all. I'm pretty sure that removeEventHandler returns false in your code.

Link to comment

Also, I don't know how often I'm saying this: code in English if you want people to look at it. Coding in German isn't practical because people may not understand it, reducing the readability of the code. It doesn't help if you additionally use some bastardized jumble of English and other languages. :P

Just a tip.

Link to comment

Sry I tried too, but I have forgotten something. I would do all what you say if it helps me, but maybe I don't think enough about it and then it's wrong what I script. But if I understand it I will script it as you said. All I would say with this is don't think, that I won't follow your tips. If I don't follow your tips than I missunderstand you.

Sry for my fucking English.

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