Overriding base functions on derma.DefineControl panels
7 replies, posted
So, atm i have a few custom controls defined inside my library. Problem is that on generic controls like DButton's DoClick function i can't seem to override it, example
In the example bellow , the text "Hey i was called instead of ..." is never ran or outputed anywhere, ie. not being called. This isn't exclusive to the DButton control too, when specified for a custom DFrame, when i specify my own SetTitle function it still calls the base function inside dframe.lua but sets the text to the default one.
I am most likely doing something wrong so any help would be appriciated
function MyButton:Init()
self.CustomText = "Hello World!"
end
function MyButton:DoClick()
end
function MyButton:DoClick() Msg("Hey, i was called instead of the base DButton:DoClick() function, yay!")
end
derma.DefineControl("DCustomButton","A Example Button", MyButton,"DButton")
You create a DoClick() function with nothing inside, you make another DoClick() function that runs a Msg() function that you didnt create anywhere.
What are you doing?
Code is here since the forum's code parsing is fucked
[Lua] Custom Button
From the given code above i expect the following output ( based on my logic, but that's incorrect aparently ( hence the question on the forums)):
>"Hello world"
>"Hey, i was called instead of the base DButton:DoClick() yay!"
( and then run the base DoClick function ( Line 10 in the pastebin file )
However , it doesn't do that and instead just immediately defaults to the Base DoClick() function inside https://github.com/Facepunch/garrysmod/blob/master/garrysmod/lua/vgui/dbutton.lua
this code confused me even more...
you call MyButton.DoClick() inside the DoClick function. You still didnt define the Msg() function anywhere, and where do you even create the button itself? with size etc.
Yep correction, Line 10 in the pastebin link should be "baseClick()" , which in turn should run the base DoClick function. My bad got mad at the formating on the forums and just decided to rewrite it on there, it's been corrected now in this post and i edited the previous. Problem still remains
http://wiki.garrysmod.com/page/Global/Msg is a default Gmod function
oh lol. i thought about that, but when seeing the basic function name "Msg" i didnt expected it to actually be a default one
Do you actually define "MyButton"?
local MyButton = {}
function MyButton:DoClick()
print("Boop")
end
derma.DefineControl("CustomDButton", "A custom DButton", MyButton, "DButton")
Sorry, you need to Log In to post a reply to this thread.