• How to make an object think?
    6 replies, posted
Something I'm working on involves a new object type, which are just tables with assigned/inherited methods and vars, only functioning clientside, and they feature functions such as Draw and Think which need to run every tick. At the moment, I just call draw for the top object in a hierarchy, draw calls think, and also draw for all child objects, and the process repeats. It doesn't feel very efficient - so, I'm wondering what calls similar functions for entities and so on, and if it's something I can/should employ, to make these methods be called automatically every tick for these objects?
The only solution is to call it in the correct hook. [code] local function Tick( ) local k, v for k, v in pairs( objects ) do if v.Tick then v:Tick( ) end end end hook.Add( "Tick", "Objects.Tick", Tick ) [/code] And so on.
Very helpful! Thanks. Haven't had to work with hooks much before, am reading up again now. If I add the hook clientside, will it only be run clientside, or should I include that condition in the function?
If you code is only ran on the client, then, yes, it will only run clientside.
whats the difference between think and tick? rate me boxes if you love me edit: it was a scam, i ment rate me love if you love me and rate me box if you hate me
from wiki.. Syntax GM:Tick( ) Description Like Think except called every tick on both client and server. Syntax GM:Think( ) Description Called every frame
[QUOTE=grunewald;26461414]from wiki.. Syntax GM:Tick( ) Description Like Think except called every tick on both client and server. Syntax GM:Think( ) Description Called every frame[/QUOTE] cool, thanks
Sorry, you need to Log In to post a reply to this thread.