AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Issue with switch statement (https://forums.alliedmods.net/showthread.php?t=340344)

GoldNux 11-12-2022 05:26

Issue with switch statement
 
Solved, I used the reserved keyword "enum". x)

I'm doing something wrong in this switch statement and I don't understand what it is.
If I remove this function code compiles as it should.

PHP Code:

public Printer(enum)
{
    switch (
enum)
    {
        case 
PRINT_T1WIN:
            
client_print(0print_center"TEAM ONE WON THE MATCH! ( %d|%d )"g_TeamOneScoreg_TeamTwoScore)
        case 
PRINT_T2WIN:
            
client_print(0print_center"TEAM TWO WON THE MATCH! ( %d|%d )"g_TeamTwoScoreg_TeamOneScore)
        case 
PRINT_DRAW:
            
client_print(0print_center"IT'S A DRAW!")
        case 
PRINT_ROUND:
            
client_print(0print_center"ROUND: %d/6"g_RoundCounter)
    }


PHP Code:

ERROR [1082]: invalid function or declaration // Function header line.
ERROR [1084]: invalid expressionassumed zero // Switch line 


MrPickles 11-12-2022 12:16

Re: Issue with switch statement
 
Quote:

Originally Posted by GoldNux (Post 2792628)
Solved, I used the reserved keyword "enum". x)

I'm doing something wrong in this switch statement and I don't understand what it is.
If I remove this function code compiles as it should.

PHP Code:

public Printer(enum)
{
    switch (
enum)
    {
        case 
PRINT_T1WIN:
            
client_print(0print_center"TEAM ONE WON THE MATCH! ( %d|%d )"g_TeamOneScoreg_TeamTwoScore)
        case 
PRINT_T2WIN:
            
client_print(0print_center"TEAM TWO WON THE MATCH! ( %d|%d )"g_TeamTwoScoreg_TeamOneScore)
        case 
PRINT_DRAW:
            
client_print(0print_center"IT'S A DRAW!")
        case 
PRINT_ROUND:
            
client_print(0print_center"ROUND: %d/6"g_RoundCounter)
    }


PHP Code:

ERROR [1082]: invalid function or declaration // Function header line.
ERROR [1084]: invalid expressionassumed zero // Switch line 


if you are not using this function in a task, it would be better to use it as stock instead of public

fysiks 11-12-2022 16:54

Re: Issue with switch statement
 
Quote:

Originally Posted by MrPickles (Post 2792663)
if you are not using this function in a task, it would be better to use it as stock instead of public

Unless it's in an include file as an optional function, it doesn't need to be a stock either. So, if it's defined in the plugin and used by the plugin, it can just be defined without type declaration.


All times are GMT -4. The time now is 15:37.

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