Raised This Month: $ Target: $400
 0% 

Switch in C/C++ like with Pawn


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 06-13-2009 , 10:08   Switch in C/C++ like with Pawn
Reply With Quote #1

Well this dont is a Amxx Scripting but someone can help me

Well How is the sintax in C/C++ to do something like

PHP Code:
// Pawn
case .. 10:
 
// Or with VB
Case 1 To 10
To do like that in C/C++

Thanks.
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
zwfgdlc
Senior Member
Join Date: May 2006
Old 06-13-2009 , 12:39   Re: Switch in C/C++ like with Pawn
Reply With Quote #2

PHP Code:
case 1:
case 
2:
case 
3:
case 
4:
case 
5:
case 
6:
case 
7:
case 
8:
case 
9:
case 
10:
{
//do somethink
}
break; 

Last edited by zwfgdlc; 06-14-2009 at 04:32.
zwfgdlc is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 06-13-2009 , 13:08   Re: Switch in C/C++ like with Pawn
Reply With Quote #3

Quote:
To specify a “range”
in the constant list, separate the lower and upper bounds of the
range with a double period (“..”). An example of a range is: “case
1..9:”.
page 116 in the pawn manual
__________________
stupok is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 06-13-2009 , 14:06   Re: Switch in C/C++ like with Pawn
Reply With Quote #4

Quote:
Originally Posted by stupok View Post
page 116 in the pawn manual
link pl0x
__________________
xPaw is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 06-13-2009 , 14:25   Re: Switch in C/C++ like with Pawn
Reply With Quote #5

Link
__________________
stupok is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-13-2009 , 16:00   Re: Switch in C/C++ like with Pawn
Reply With Quote #6

Aren't you trying to do this in C++? How is the Pawn manual relevant?
__________________
Bugsy is offline
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 06-13-2009 , 18:45   Re: Switch in C/C++ like with Pawn
Reply With Quote #7

If I set case 1..9: Dont compile, I test with 4 compilers
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-13-2009 , 20:08   Re: Switch in C/C++ like with Pawn
Reply With Quote #8

I did some searching and found C++ doesn't support value ranges in switch statements. I guess you are stuck with if's.
__________________
Bugsy is offline
Owyn
Veteran Member
Join Date: Nov 2007
Old 06-14-2009 , 03:30   Re: Switch in C/C++ like with Pawn
Reply With Quote #9

show full code i'd say, i didn't test cases much but i guess Case 1 To 10: should be ok for int , i used it only on strings, therefore sometimes switch is more problematic than if + else if statements and requires some tweaking like setting up breaks and default case

ps-*wish there were a c++ forum like allied mods with all open sources and scripting help like for pawn xD
__________________
☜ Free Mozy ☂backup\҉sync user
Quote:
Американский форум - Задаёшь вопрос, потом тебе отвечают.
Израильский форум - Задаёшь вопрос, потом тебе задают вопрос.
Русский форум - Задаёшь вопрос, потом тебе долго рассказывают, какой ты мудак.
Owyn is offline
Send a message via ICQ to Owyn
ehha
SourceMod Donor
Join Date: Apr 2006
Location: Sibiu
Old 06-14-2009 , 04:45   Re: Switch in C/C++ like with Pawn
Reply With Quote #10

I just added this line in a switch:
Pawn:
Code:
case 100 .. 200: client_print(id, print_console, "You fail!");
Compiles OK & works.

C++
Code:
case 100 ... 200: cout << "I failz" << endl;
Compiles OK & works.

Last edited by ehha; 06-14-2009 at 05:14.
ehha 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 13:54.


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