Appension

All classes in TDLib do their magic through appension - adding code to a preexisting function in a way which does not overwrite the original definition.

On(name, func)

Function appension is done through the On meta function, a TDLib function which exists on any panel object. This will cause the function in the second argument to be executed alongside anything thats already there, instead of straight up overwriting it.

Example usage
panel:On("DoClick", function(s) print("I was clicked") end)

You should use this wherever possible, so that you do not override classes which you just applied.

Bad
but:NetMessage("SomeMessage") --This class appends a function which sends a net message on DoClick.
but.DoClick = function(s)
    print("hi") -- THE NET MESSAGE WILL NOT BE SENT IF YOU OVERWRITE DOCLICK!
end
Good
but:NetMessage("SomeMessage")
but:On("DoClick", function(s)
    print("hi") -- Everyone lives happily ever after, the net message is sent, and this is printed
end)

Appension Overwrites

Appension overwrites let you set the function which will be overwritten by every future On() call to a panel.

Usage demonstration
but:SetAppendOverwrite("DoRightClick") -- Make all future appensions use DoRightClick 
but:On("DoClick", function(s)
    print("clicked") -- This will now be ran in DoRightClick vs. DoClick, as per the overwrite above, despite us appending this to DoClick
end)

but:ClearAppendOverwrite() -- Clear the overwrite, returning everything to how it was earlier
but:On("DoClick", function(s)
    print("clicked") -- Ran in doclick as stated in the :On(), as we cleared the appension
end)

A very useful example of this is when a class appends code to a button's DoClick function, but you want it to apply to DoRightClick instead.

Example of changing a net message to fire on rightclick instead of leftclick
but:SetAppendOverwrite("DoRightClick")
but:NetMessage("BuyWeapon")

results matching ""

    No results matching ""