Raised This Month: $ Target: $400
 0% 

Variable life time?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Flasher
Senior Member
Join Date: Apr 2008
Old 02-17-2009 , 02:25   Re: Variable life time?
Reply With Quote #4

Thanks Vet and Bugsy!

Quote:
Originally Posted by Vet View Post
In the example you cited, I'd assume the author was referring the the value of the variable being deleted rather than the variable itself.
Variable discussed is an array and if it is destroyed, I think value should be lost.
Quote:
Originally Posted by Vet View Post
In your code, you don't really need to sent a parameter. You could simplely obtain the plrid again by subtracting out the BASE_TASK_ID
Thanks, I thinked about such way as a backup.

Quote:
Originally Posted by Vet View Post
Typically, the scope of a variable is only as wide as the routine its defined in. Thus, the life of your variables is only valid as long as each routine is executing. As soon as the sub/function is exited, the variables are released. A variable defined globally (not within a sub/function, like args in the second example)), lives and is visible throughout the entire plugin.
Quote:
Originally Posted by Bugsy View Post
The variable will be passed without issue
So can we came to one opinion about variable lifetime?

Quote:
Originally Posted by Bugsy View Post
but you need to do additional checking in showinfo to confirm the player is still connected after 30 seconds.
ie.
- id 21 connects
- set_task called with id 21 as a param
- 10 seconds later id 21 disconnects
- 20 seconds later, showInfo(21) gets called from set_task but player no longer connected. any functions called on id 21 will error without first checking is_user_connected()
Thanks for this valuable notice.
BTW If we have
PHP Code:
public client_disconnect(plrid)
{
    
remove_task(BASE_TASK_ID plrid);
    return 
PLUGIN_CONTINUE;

will this be enough to skip checking is_user_connected()?

Last edited by Flasher; 02-17-2009 at 02:40.
Flasher is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:04.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode