How do you hook in to functions?
Hello again, here I am seeking aid from people more knowledgable in the arts of coding than I.
This day, I'm trying to add some functionality to an existing function in the ns2 code. Specifically the ResourcePoint:Reset() function. Here's the code I tried:
Obviously, this isn't working, meaning I've done something wrong.
It would be fantastic if someone would explain to me what I've done wrong, and optionally why what I tried was wrong.
All the best,
Ironsoul.
This day, I'm trying to add some functionality to an existing function in the ns2 code. Specifically the ResourcePoint:Reset() function. Here's the code I tried:
Script.Load("lua/ResourcePoint.lua") do local oldResourcePointReset = ResourcePoint:Reset() ResourcePoint:Reset = function() oldResourcePointReset() Print("Resource Point detected") //attempted hook in end end
Obviously, this isn't working, meaning I've done something wrong.
It would be fantastic if someone would explain to me what I've done wrong, and optionally why what I tried was wrong.
All the best,
Ironsoul.
Comments
Youre mixing up the self call syntax ":" with the normal "." style access should be and you need to capture and pass the self parameter to the original function since you're not defining the function with self call syntax which implicitly includes the self parameter
In this example we hook into the Create function to add a new mixin to grenade launchers. We can also add new networkVars into the networkVars table at the top, and they will get added to the class: