AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Bool Value Bug (https://forums.alliedmods.net/showthread.php?t=99892)

lolzin123 08-10-2009 12:43

Bool Value Bug
 
I use this case to changing the bool , but when it's turn on... never turn off again. :D
PHP Code:

case 5// BOOL
        
{
            if (
g_bool[id] == true
            { 
                
g_bool[id] = false ;
            } 
            if (
g_bool[id] == false
            { 
                
g_bool[id] = true ;
            } 
        } 

:|

AntiBots 08-10-2009 12:44

Re: Bool Value Bug
 
in second if use "else if"

also you can use

g_bool[id] = !g_bool[id];

lolzin123 08-10-2009 13:09

Re: Bool Value Bug
 
but this gonna make the effect of turn ON and OFF ?

"g_bool[id] = !g_bool[id];"

AntiBots 08-10-2009 13:11

Re: Bool Value Bug
 
Yes

lolzin123 08-10-2009 13:15

Re: Bool Value Bug
 
TNX man :D

fysiks 08-10-2009 13:31

Re: Bool Value Bug
 
Quote:

Originally Posted by lolzin123 (Post 895410)
but this gonna make the effect of turn ON and OFF ?

"g_bool[id] = !g_bool[id];"

This method is a toggle. It will always change it to true if it's false or to false if it's true, which is what you were trying to do with your if statement.

One 08-10-2009 18:22

Re: Bool Value Bug
 
Quote:

Originally Posted by fysiks (Post 895433)
This method is a toggle. It will always change it to true if it's false or to false if it's true, which is what you were trying to do with your if statement.

crash ?!

Exolent[jNr] 08-10-2009 19:23

Re: Bool Value Bug
 
How would that crash?

Code:
new bool:g_bTestBool = true; public MyFunction( ) {     g_bTestBool = !g_bTestBool;         // setting it to the value OPPOSITE of what it currently is     // true = !false ( !false reads as "not false", and true is not false )     // false = !true ( !true reads as "not true", and false is not true )         // if g_bTestBool = true     // g_bTestBool = !true = false         // if g_bTestBool = false     // g_bTestBool = !false = true         // it is the same as this code     if( g_bTestBool ) // check if true     {         g_bTestBool = false;     }     else // g_bTestBool is false     {         g_bTestBool = true;     } }

fysiks 08-10-2009 20:55

Re: Bool Value Bug
 
Quote:

Originally Posted by One (Post 895707)
crash ?!

I tested it before I posted.

One 08-11-2009 02:26

Re: Bool Value Bug
 
& i tested after i posted. i did it in task & got crashed :Pmaybe i did anything wrong but i got crashed in loop


All times are GMT -4. The time now is 18:24.

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