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

How do I use a switch?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
headline
SourceMod Moderator
Join Date: Mar 2015
Old 06-28-2015 , 02:38   How do I use a switch?
Reply With Quote #1

I have never seen more errors than this. I get errors from includes when this code is in and I have NO clue as to why these are happening to me. I appear to be using these right so someone please enlighten me.

You should be able to see why I am using switches instead of a bunch of else ifs. When I was using else ifs It wasnt reliable and I was hoping this would be a better solution.
PHP Code:
    if (GetPlayerCount() == 1)
    {
        switch (
iAnnual)
        {
            case 
1:
            {
                
CPrintToChatAll("{DARKRED}[AG] {GREEN}Hunger Games {NORMAL}: \"{PINK}%N{NORMAL}\" is the victor of the {PINK}%dst {NORMAL}Annual Hunger Games!"clientiAnnual);
            }
            case 
2:
            {
                
CPrintToChatAll("{DARKRED}[AG] {GREEN}Hunger Games {NORMAL}: \"{PINK}%N{NORMAL}\" is the victor of the {PINK}%dnd {NORMAL}Annual Hunger Games!"clientiAnnual);
            }
            case 
3:
            {
                
CPrintToChatAll("{DARKRED}[AG] {GREEN}Hunger Games {NORMAL}: \"{PINK}%N{NORMAL}\" is the victor of the {PINK}%drd {NORMAL}Annual Hunger Games!"clientiAnnual);
            }
            case 
.. 20:
            {
                
CPrintToChatAll("{DARKRED}[AG] {GREEN}Hunger Games {NORMAL}: \"{PINK}%N{NORMAL}\" is the victor of the {PINK}%dth {NORMAL}Annual Hunger Games!"clientiAnnual);
            }
            default:
            {
                
CPrintToChatAll("{DARKRED}[AG]{GREEN} Hunger Games{NORMAL}: The tribute \"%N\" has died. {PINK}%d {NORMAL} tributes remain."victimiRemaining);
            }
        }
    } 
Code:
C:\Users\Studio\Desktop\Scripting\include\menus.inc(372) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Studio\Desktop\Scripting\include\emitsoundany.inc(153) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Studio\Desktop\Scripting\include\csgocolors.inc(118) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Studio\Desktop\Scripting\include\csgocolors.inc(325) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Studio\Desktop\Scripting\include\csgocolors.inc(390) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Studio\Desktop\Scripting\include\csgocolors.inc(481) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Studio\Desktop\Scripting\awdawd.sp(106) : warning 219: local variable "i" shadows a variable at a preceding level
C:\Users\Studio\Desktop\Scripting\awdawd.sp(148) : error 001: expected token: ":", but found ".."
C:\Users\Studio\Desktop\Scripting\awdawd.sp(148) : warning 215: expression has no effect
C:\Users\Studio\Desktop\Scripting\awdawd.sp(148) : error 001: expected token: ";", but found ":"
C:\Users\Studio\Desktop\Scripting\awdawd.sp(152) : error 014: invalid statement; not in switch
C:\Users\Studio\Desktop\Scripting\awdawd.sp(152) : error 029: invalid expression, assumed zero
C:\Users\Studio\Desktop\Scripting\awdawd.sp(154) : error 017: undefined symbol "iRemaining"
C:\Users\Studio\Desktop\Scripting\awdawd.sp(160) : error 122: expected type expression
C:\Users\Studio\Desktop\Scripting\awdawd.sp(160) : error 021: symbol already defined: "EmitSoundToAllAny"
C:\Users\Studio\Desktop\Scripting\awdawd.sp(162) : error 010: invalid function or declaration
C:\Users\Studio\Desktop\Scripting\awdawd.sp(164) : error 010: invalid function or declaration
C:\Users\Studio\Desktop\Scripting\awdawd.sp(170) : error 122: expected type expression
C:\Users\Studio\Desktop\Scripting\awdawd.sp(170) : error 021: symbol already defined: "CPrintToChat"
C:\Users\Studio\Desktop\Scripting\awdawd.sp(171) : error 010: invalid function or declaration
C:\Users\Studio\Desktop\Scripting\awdawd.sp(173) : error 021: symbol already defined: "CPrintToChat"
C:\Users\Studio\Desktop\Scripting\awdawd.sp(174) : error 054: unmatched closing brace ("}")
C:\Users\Studio\Desktop\Scripting\awdawd.sp(166) : warning 203: symbol is never used: "__unknown__"
C:\Users\Studio\Desktop\Scripting\awdawd.sp(166) : warning 203: symbol is never used: "i"
headline is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 06-28-2015 , 02:40   Re: How do I use a switch?
Reply With Quote #2

You're going to need to post more of the code.
__________________
ddhoward is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 06-28-2015 , 02:48   Re: How do I use a switch?
Reply With Quote #3

Quote:
Originally Posted by ddhoward View Post
You're going to need to post more of the code.
When I remove this, I get no errors...
headline is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 06-28-2015 , 05:43   Re: How do I use a switch?
Reply With Quote #4

PHP Code:
case 4567891011121314151617181920:

    
CPrintToChatAll("{DARKRED}[AG] {GREEN}Hunger Games {NORMAL}: \"{PINK}%N{NORMAL}\" is the victor of the {PINK}%dth {NORMAL}Annual Hunger Games!"clientiAnnual);

Kailo is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 06-28-2015 , 05:45   Re: How do I use a switch?
Reply With Quote #5

Quote:
Originally Posted by Kailo View Post
PHP Code:
case 4567891011121314151617181920:

    
CPrintToChatAll("{DARKRED}[AG] {GREEN}Hunger Games {NORMAL}: \"{PINK}%N{NORMAL}\" is the victor of the {PINK}%dth {NORMAL}Annual Hunger Games!"clientiAnnual);

Ahhh. Thank you. I cant believe one little mistake caused all of those errors
headline 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 20:07.


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