Errors from deleted entity.

Hello,

I’ve created some scripts that allow a user to write some code, have it compiled into a script and put in a sandboxed fenv, however the issue is when the user codes in a timer.

For example: user codes in a looping timer that constantly moves a box on the screen, the box is moved with a function tied to an entity, when the entity is removed; the function is also removed, so now I have sandboxed code, trying to run a function that does not exist anymore (because the entity was deleted), my question is; is there a way I can stop these errors from appearing if the entity was to be released, sure it could be coded into the users code; but I don’t want to trust the player all the time.

Any ideas? Thanks.

Check the entity they’re using is still valid before executing the function.

[editline]16th September 2016[/editline]

Or use this hook to manage their timers: https://wiki.garrysmod.com/page/GM/EntityRemoved

Thanks for the reply :smiley:

I managed to sort something out before I saw your post, basically just pcall’d it in another function

local safecall = function() pcall(finalfunc) end