'LinKin Posted August 16, 2014 Share Posted August 16, 2014 Hi, I'm using a timer and passing a player as an argument; setTimer(Func, 3000, 1, aPlayer) So, inside the implementation of the 'Func' function, how can I check if the player that I passed to it still exists? Would it be enough to make: function Func(thePlayer) if thePlayer then code... end end ? Sometimes our scripts show warnings saying things such as "Bad player 'element' pointer (1)" so if that would be the case in this script, thePlayer variable would still be true. I was thinking about getElementType(thePlayer) == "player" But still not sure Link to comment
DiSaMe Posted August 16, 2014 Share Posted August 16, 2014 Values of variables don't change themselves, so condition evaluates to true. Using getElementType will help, but it will still output a warning message if passed element does not exist. To avoid warnings, check element's existence with isElement before checking its type. However, even then the code is not guaranteed to work fine. If element gets destroyed and another one gets created, it's possible for new element to get the same ID (or memory address, I'm not sure what it is, but it doesn't matter) which the previous element had. If that happens, variables which held the value of previous element will start referring to the new element. So if one player quits and another one joins when the timer is still running, it's not impossible for the timer to do stuff with the new player. To guarantee that it won't happen, you need to kill the timer with killTimer when player quits instead of checking player's existence in the timer. Link to comment
'LinKin Posted August 16, 2014 Author Share Posted August 16, 2014 Yes, isElement should do fine. Thanks. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now