Raised This Month: $51 Target: $400
 12% 

help me with switch


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
anderpp
Junior Member
Join Date: Feb 2018
Old 08-22-2018 , 22:36   help me with switch
Reply With Quote #1

I have this structure
PHP Code:
const numberofcolor 7
new const linecolors[numberofcolor][] = {
    
"White",
    
"Green",
    
"Blue",
    
"White",
    
"Red",
    
"Black",
    
"Red"
}

switch(
linecolors[1][]) {
    case 
"White":
    {
        
write_byte(255// R
        
write_byte(255// G
        
write_byte(255// B
    
}
    case 
"Green":
    {
        
write_byte(20// R
        
write_byte(190// G
        
write_byte(0// B
    
}

how to compare the information in the array through the switch?
anderpp is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-23-2018 , 00:34   Re: help me with switch
Reply With Quote #2

As far as I know you can't use chars with switches. You are pretty much creating a characters array and you would have to use strcmp.
__________________
Spirit_12 is offline
anderpp
Junior Member
Join Date: Feb 2018
Old 08-23-2018 , 00:54   Re: help me with switch
Reply With Quote #3

Quote:
Originally Posted by Spirit_12 View Post
As far as I know you can't use chars with switches. You are pretty much creating a characters array and you would have to use strcmp.
Thank you! Solved, statement if with strcmp.
anderpp is offline
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 08-23-2018 , 05:40   Re: help me with switch
Reply With Quote #4

Quote:
Originally Posted by Spirit_12 View Post
As far as I know you can't use chars with switches. You are pretty much creating a characters array and you would have to use strcmp.
not chars, char arrays*.
better switch with first character ('W', 'R'...) rather than using strcmp
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM

Last edited by Ghosted; 08-23-2018 at 06:55.
Ghosted is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-23-2018 , 12:52   Re: help me with switch
Reply With Quote #5

Quote:
Originally Posted by Ghosted View Post
not chars, char arrays*.
better switch with first character ('W', 'R'...) rather than using strcmp
He has multiple colors starting with same first letter for example black and blue share same first letter. Switch won't work, unless the characters are changed to unique words. String compare is not a bad idea considering we got less than 10 comparisons.
__________________
Spirit_12 is offline
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 08-23-2018 , 12:57   Re: help me with switch
Reply With Quote #6

Quote:
Originally Posted by Spirit_12 View Post
He has multiple colors starting with same first letter for example black and blue share same first letter. Switch won't work, unless the characters are changed to unique words. String compare is not a bad idea considering we got less than 10 comparisons.
Haven't seen all color names, string comparison & elseifs is not so good. My problem can be solved with that idea making first character unique, that should be one of the great solutions for this thread.
@anderpp u can optimize that code and make smaller:
Code:
const numberofcolor = 7 
new const linecolors[numberofcolor][] =
{ 
    {R,G,B},
    {R,G,B],
    etc...
} 

write_byte(linecolors[colorID][0]) // R 
write_byte(linecolors[colorID][1]) // G 
write_byte(linecolors[colorID][2]) // B
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM

Last edited by Ghosted; 08-23-2018 at 13:01.
Ghosted is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-23-2018 , 13:17   Re: help me with switch
Reply With Quote #7

Comparing strings and using else if is not going to cause anything to explode. I don't see the point in over complicating things, especially if OP is a beginner.
__________________
HamletEagle is online now
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 08-23-2018 , 15:31   Re: help me with switch
Reply With Quote #8

If you don't use the "if" statment to compare your strings with more than one char, how you're going to compare them?
__________________








CrazY. is offline
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 08-23-2018 , 16:10   Re: help me with switch
Reply With Quote #9

Quote:
Originally Posted by CrazY. View Post
If you don't use the "if" statment to compare your strings with more than one char, how you're going to compare them?
simple, not use them.
in amxx never used strings after plugin_cfg
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM
Ghosted 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 06:03.


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