Raised This Month: $32 Target: $400
 8% 

bool check


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 06-27-2015 , 07:49   bool check
Reply With Quote #1

For example I have this function

PHP Code:
public Ham_Spawn_Postid )
{
    if( !
is_user_aliveid ) )
        return 
HAM_IGNORED;

    
g_bAliveid ] = true;

Should I always check, is it false before setting it true?

PHP Code:
public Ham_Spawn_Postid )
{
    if( !
is_user_aliveid ) )
        return 
HAM_IGNORED;

    if( !
g_bAliveid ] )
        
g_bAliveid ] = true;

Or this make no sense?

Last edited by ~Ice*shOt; 06-27-2015 at 07:49.
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-27-2015 , 08:07   Re: bool check
Reply With Quote #2

The check is useless in this context.
__________________

Last edited by HamletEagle; 06-27-2015 at 08:08.
HamletEagle is offline
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 06-27-2015 , 08:12   Re: bool check
Reply With Quote #3

Can you give an example where it could be useful?
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
wickedd
Veteran Member
Join Date: Nov 2009
Old 06-27-2015 , 08:20   Re: bool check
Reply With Quote #4

You should, but it isn't necessary.

Quote:
Originally Posted by ~Ice*shOt View Post
Can you give an example where it could be useful?
PHP Code:
#include <amxmodx>

new bool:your_bool33 ]

public 
plugin_init( )
{
    
register_clcmd"say /test","try_this")
}

public 
client_connectid )
{
    
your_boolid ] = false
}

public 
try_thisid )
{
    if( !
your_boolid ] )
    {
        
client_printidprint_chat"It works" )
        
your_boolid ] = true;
    }
    else
    {
        
client_printidprint_chat"You tried it already" )
    }

Lets say you want a player to able to use a cmd only once, you can do something like this.
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd is offline
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 06-27-2015 , 08:25   Re: bool check
Reply With Quote #5

OK, but checking in my example is necessary, let's say there are 1 terrorist and 2 cts (g_bAlive[ id ] = true), that one terrorist kill 2 cts (g_bAlive[ id ] = false). On spawn it is setting again g_bAlive[ id ] = true for both team players, but terrorist already have this bool true (because he didn't died in previous round) so it would be pointless to set it twice. My question is there's difference if I set it true twice, or better check and don't set if it is already true?

Last edited by ~Ice*shOt; 06-27-2015 at 08:27.
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
wickedd
Veteran Member
Join Date: Nov 2009
Old 06-27-2015 , 08:28   Re: bool check
Reply With Quote #6

Yes it would be pointless, but it wont affect anything by setting it true again is my point.
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-27-2015 , 08:55   Re: bool check
Reply With Quote #7

IIRC when you set a value to a var it doesn't use any memory, it use memory only when it is created, so setting again is not a problem.
__________________

Last edited by HamletEagle; 06-27-2015 at 08:56.
HamletEagle is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 06-27-2015 , 11:36   Re: bool check
Reply With Quote #8

Just setting it should be faster then checking if it was already set beforehand, although it's just trivial difference. Anyway, there's no need to check for variable's value first.
klippy is offline
Reply


Thread Tools
Display Modes

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 00:05.


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