AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Switch in C/C++ like with Pawn (https://forums.alliedmods.net/showthread.php?t=94629)

AntiBots 06-13-2009 10:08

Switch in C/C++ like with Pawn
 
Well this dont is a Amxx Scripting but someone can help me :P

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.

zwfgdlc 06-13-2009 12:39

Re: Switch in C/C++ like with Pawn
 
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; 


stupok 06-13-2009 13:08

Re: Switch in C/C++ like with Pawn
 
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

xPaw 06-13-2009 14:06

Re: Switch in C/C++ like with Pawn
 
Quote:

Originally Posted by stupok (Post 848097)
page 116 in the pawn manual

link pl0x

stupok 06-13-2009 14:25

Re: Switch in C/C++ like with Pawn
 
Link

Bugsy 06-13-2009 16:00

Re: Switch in C/C++ like with Pawn
 
Aren't you trying to do this in C++? How is the Pawn manual relevant?

AntiBots 06-13-2009 18:45

Re: Switch in C/C++ like with Pawn
 
If I set case 1..9: Dont compile, I test with 4 compilers :P

Bugsy 06-13-2009 20:08

Re: Switch in C/C++ like with Pawn
 
I did some searching and found C++ doesn't support value ranges in switch statements. I guess you are stuck with if's.

Owyn 06-14-2009 03:30

Re: Switch in C/C++ like with Pawn
 
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

ehha 06-14-2009 04:45

Re: Switch in C/C++ like with Pawn
 
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.


All times are GMT -4. The time now is 13:54.

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