Raised This Month: $ Target: $400
 0% 

bool question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 04-22-2013 , 23:11   bool question
Reply With Quote #1

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 ?
__________________

Last edited by Blizzard_87; 04-22-2013 at 23:27.
Blizzard_87 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-23-2013 , 00:17   Re: bool question
Reply With Quote #2

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 ;)
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 04-23-2013 at 00:19.
ConnorMcLeod is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 04-23-2013 , 00:20   Re: bool question
Reply With Quote #3

Since a bool can only be true or false, why use are you using a switch instead of an if?
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-23-2013 , 00:39   Re: bool question
Reply With Quote #4

+1
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 04-23-2013 , 00:42   Re: bool question
Reply With Quote #5

@ 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.
__________________
Blizzard_87 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-23-2013 , 01:15   Re: bool question
Reply With Quote #6

Quote:
Originally Posted by Blizzard_87 View Post
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.
__________________
fysiks is offline
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 04-23-2013 , 01:21   Re: bool question
Reply With Quote #7

Quote:
Originally Posted by fysiks View Post
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
__________________

Last edited by Blizzard_87; 04-23-2013 at 01:21.
Blizzard_87 is offline
Podarok
BANNED
Join Date: Jan 2011
Location: Narnia
Old 04-23-2013 , 02:27   Re: bool question
Reply With Quote #8

Quote:
Originally Posted by Blizzard_87 View Post
@ conner.
Connor gonna get mad
Podarok is offline
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 04-23-2013 , 02:34   Re: bool question
Reply With Quote #9

Quote:
Originally Posted by Podarok View Post
Connor gonna get mad
what's this got to do with bools?
__________________
Blizzard_87 is offline
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 04-23-2013 , 02:38   Re: bool question
Reply With Quote #10

just to clarify each time this is called it will change true or false?

hmm = !hmm
__________________
Blizzard_87 is offline
Reply



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 10:53.


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