• how can i use callback function?
    7 replies, posted
i hope to make a function for creating models simply [code] function TestModel(pos,model,callback) local ent = ents.CreateClientProp() ent:SetPos(pos) ent:SetAngles(Angle(0,0,0)) ent:SetModel(model) ent.RenderOverride() = function() ---------- i hope to adding callback in this line -------- callback(ent) end [/code] usage [code] TestModel(self:GetPos(), "models/hunter/plates/plate1x1.mdl", function(ent) ent:DrawModel() print("ent test!") end) [/code] i already asked about this question but answers did not help.
I already told you what to do in your last thread: you just set ent.RenderOverride to callback, you don't wrap it in another function. I also don't get why you're adding parentheses next to RenderOverride.
You got pretty accurate answers in the previous thread. If you want ent.RenderOverride to do something, simply add the code inside of the function, it's pretty simple.
[QUOTE=code_gs;52402223]I already told you what to do in your last thread: you just set ent.RenderOverride to callback, you don't wrap it in another function. I also don't get why you're adding parentheses next to RenderOverride.[/QUOTE] then i can't never ever adding callback into ent.RenderOverride? [code] you mean ent.RenderOverride() = callback but my hope is ent.RenderOverride() = function() callback() with E.T.C end so i hope to add some code inside of ent.RenderOverride() with callback() [/code]
So how about you put the rest of the code into callback? :/
[QUOTE=SleepyMode;52402238]So how about you put the rest of the code into callback? :/[/QUOTE] the reason why i want to do this is because it's more simple..
-snip-
[lua]function ent:RenderOverride() self:DrawModel() -- default behavior -- any code you want end[/lua] or, if you want to use the same function for many different entities: [lua]local function YourRenderFunction(self) self:DrawModel() -- default behavior -- any code you want end -- ... later, probably in some hook where you have an ent ent.RenderOverride = YourRenderFunction -- notice, no parentheses in this line![/lua]
Sorry, you need to Log In to post a reply to this thread.