AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   bool question (https://forums.alliedmods.net/showthread.php?t=214093)

Blizzard_87 04-22-2013 23:11

bool question
 
is it possible to have bools in the function brackets?

public function(id, bool:etc )
{

}


and then you can just do this in other functions..


function(id, true)

or

function(id, false)

if so how to i make up the function with the bool ?

EDIT:
ok figured one way out

PHP Code:

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /true""cmdTest"0);
    
register_clcmd("say /false""cmdTest1"0);
}

public 
cmdTest(id)
{
    
Test(idtrue)    
}

public 
cmdTest1(id)
{
    
Test(idfalse)
}

public 
Test(idbool:hmm )
{
    switch(
hmm)
    {
        case 
trueclient_print(idprint_center"I AM TRUE");
        case 
falseclient_print(idprint_center"I AM FALSE");
    }


is there any other more effective ways ?

ConnorMcLeod 04-23-2013 00:17

Re: bool question
 
Efficienty is not the question here, code is correct.
But, depending on your need, if you don't choose the correct way to do something, code won't be efficient, but without concrete example, nobody can say ;)

YamiKaitou 04-23-2013 00:20

Re: bool question
 
Since a bool can only be true or false, why use are you using a switch instead of an if?

ConnorMcLeod 04-23-2013 00:39

Re: bool question
 
+1

Blizzard_87 04-23-2013 00:42

Re: bool question
 
@ conner. Thanks

@ YamiKaitou. so when using a bool. having if is less code so it's better?

just trying out new ways of doing things. And now I know my code was okay I can now work out what to use with it.

fysiks 04-23-2013 01:15

Re: bool question
 
Quote:

Originally Posted by Blizzard_87 (Post 1938039)
so when using a bool. having if is less code so it's better?

A switch is not intended to be used for booleans since a switch is designed for integers (when more than two cases are possible). Use an if statement.

Blizzard_87 04-23-2013 01:21

Re: bool question
 
Quote:

Originally Posted by fysiks (Post 1938053)
A switch is not intended to be used for booleans since a switch is designed for integers (when more than two cases are possible). Use an if statement.

thanks for your help guys :)

Podarok 04-23-2013 02:27

Re: bool question
 
Quote:

Originally Posted by Blizzard_87 (Post 1938039)
@ conner.

Connor gonna get mad :D

Blizzard_87 04-23-2013 02:34

Re: bool question
 
Quote:

Originally Posted by Podarok (Post 1938067)
Connor gonna get mad :D

what's this got to do with bools?

Blizzard_87 04-23-2013 02:38

Re: bool question
 
just to clarify each time this is called it will change true or false?

hmm = !hmm


All times are GMT -4. The time now is 10:53.

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