AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   a simple question / case('X'): (https://forums.alliedmods.net/showthread.php?t=134627)

SpokY 08-07-2010 09:26

a simple question / case('X'):
 
Hello,
when i use the case('1'): till case('9'): it works fine to compile but when i use case('8'): till case('12'): he says me en error :

Code:

/groups/amxmodx/tmp3/text43obsz.sma(940) : warning 213: tag mismatch
/groups/amxmodx/tmp3/text43obsz.sma(1743) : error 027: invalid character constant
/groups/amxmodx/tmp3/text43obsz.sma(1743) : warning 215: expression has no effect
/groups/amxmodx/tmp3/text43obsz.sma(1743) : error 001: expected token: ";", but found ":"
/groups/amxmodx/tmp3/text43obsz.sma(1748) : error 014: invalid statement; not in switch
/groups/amxmodx/tmp3/text43obsz.sma(1748) : error 027: invalid character constant
/groups/amxmodx/tmp3/text43obsz.sma(1748) : warning 215: expression has no effect
/groups/amxmodx/tmp3/text43obsz.sma(1748) : error 001: expected token: ";", but found ":"

BUT THIS ERROR IS ONLY WHEN I USE case('8'): till case('12'): why?
How i can fix it?

Thanks a lot !!!

Hunter-Digital 08-07-2010 09:35

Re: a simple question / case('X'):
 
Show code, case is not a function, don't place ( and ) after it.

I am assuming you're using switch().
Code:

switch(variable)
{
    case 1: // variable is 1
    case 2..5: // variable is between 2 and 5
    default: // variable is none of above
}

If you use '8' it will be considered 8 as string, use that if you're checking a string.

Code:

new szText[] = "abc123"

switch(szText[0]) // "a"
{
      case 'a': // this will trigger
}

switch(szText[4]) // "2"
{
      case 2: // this won't trigger
      case '2': // this one will trigger
}


SpokY 08-07-2010 09:42

Re: a simple question / case('X'):
 
Thanks for the fast answer but i didnt understand you..
here is a part of the code :

Code:


    formatex(menuname, charsmax(menuname), "%L", LANG_SERVER, "JBE_MENU_LASTREQ")
    menu = menu_create(menuname, "lastrequest_select")

    formatex(option, charsmax(option), "%L", LANG_SERVER, "JBE_MENU_LASTREQ_OPT1")
    menu_additem(menu, option, "1", 0)

    formatex(option, charsmax(option), "%L", LANG_SERVER, "JBE_MENU_LASTREQ_OPT2")
    menu_additem(menu, option, "2", 0)

    formatex(option, charsmax(option), "%L", LANG_SERVER, "JBE_MENU_LASTREQ_OPT3")
    menu_additem(menu, option, "3", 0)

    formatex(option, charsmax(option), "%L", LANG_SERVER, "JBE_MENU_LASTREQ_OPT8")
    menu_additem(menu, option, "8", 0)

    formatex(option, charsmax(option), "%L", LANG_SERVER, "JBE_MENU_LASTREQ_OPT9")
    menu_additem(menu, option, "9", 0)

    formatex(option, charsmax(option), "%L", LANG_SERVER, "JBE_MENU_LASTREQ_OPT10")
    menu_additem(menu, option, "10", 0)

    formatex(option, charsmax(option), "%L", LANG_SERVER, "JBE_MENU_LASTREQ_OPT11")
    menu_additem(menu, option, "11", 0)

    formatex(option, charsmax(option), "%L", LANG_SERVER, "JBE_MENU_LASTREQ_OPT12")
    menu_additem(menu, option, "12", 0)

an here the other part :

Code:


        case('8'):
        {
            formatex(option, charsmax(option), "%L", LANG_SERVER, "JBE_MENU_LASTREQ_SEL8", dst)
            player_hudmessage(0, 6, 3.0, {0, 255, 0}, option)
        }
        case('9'):
        {
            formatex(option, charsmax(option), "%L", LANG_SERVER, "JBE_MENU_LASTREQ_SEL9", dst)
            player_hudmessage(0, 6, 3.0, {0, 255, 0}, option)
        }
        case('10'):
        {
            formatex(option, charsmax(option), "%L", LANG_SERVER, "JBE_MENU_LASTREQ_SEL10", dst)
            player_hudmessage(0, 6, 3.0, {0, 255, 0}, option)
        }
        case('11'):
        {
            formatex(option, charsmax(option), "%L", LANG_SERVER, "JBE_MENU_LASTREQ_SEL11", dst)
            player_hudmessage(0, 6, 3.0, {0, 255, 0}, option)
        }
        case('12'):
        {
            formatex(option, charsmax(option), "%L", LANG_SERVER, "JBE_MENU_LASTREQ_SEL12", dst)
            player_hudmessage(0, 6, 3.0, {0, 255, 0}, option)
        }


Hunter-Digital 08-07-2010 09:48

Re: a simple question / case('X'):
 
Pff, what a waste of 5 minutes...

Read my post again, case is not a function and you MUST NOT add ( and ) to it, see my examples.

Seta00 08-07-2010 10:32

Re: a simple question / case('X'):
 
That's not the problem, your problem is case '12'.
Case receives a cell value, and '12' is a string with two cells.

Also, ' is used for chars only, you have to use " for strings.

fysiks 08-07-2010 13:22

Re: a simple question / case('X'):
 
You will need to do it like it is shown in the new menus tutorial.


All times are GMT -4. The time now is 00:17.

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