Author Topic: switch case help  (Read 3926 times)

0 Members and 1 Guest are viewing this topic.

Offline ramandu

  • Street Thug
  • *
  • Posts: 16
    • View Profile
switch case help
« on: March 03, 2010, 03:43:28 pm »
i'm trying to make a command group hierarchy.

if the players primary group is any of the four in the "case" statement, he has access to all of that groups commands.

but as soon as i increase any of the "case" values above two characters, it throws many compile errors.


Code: [Select]
stock
IsPlayerGroup_Mod(Player[], Primary_Group[])
{

switch (Primary_Group[0])
{


// case 'a', 'b', 'c', 'd' : // ->  works
// case '1', '2', '3', '4': // -> This works too

case 'USER', 'ADMIN', 'HALF-ADMIN', 'MODERATOR': // -> but this dosnt work, why ?
{
return 1;

}
}
return 0;
}

calling syntax: IsPlayerGroup_Mod("Ramandu", "ADMIN");

how do i solve it ?

thankyou very much
« Last Edit: March 03, 2010, 03:50:41 pm by ramandu »

Offline Boss

  • VC:MP Beta Tester (inactive)
  • Made Man
  • *
  • Posts: 229
  • Boss
    • View Profile
    • TDH Clan Site
Re: switch case help
« Reply #1 on: March 03, 2010, 04:26:39 pm »
Afair ' is used for characters only. Use " for strings.

Offline ramandu

  • Street Thug
  • *
  • Posts: 16
    • View Profile
Re: switch case help
« Reply #2 on: March 03, 2010, 04:43:34 pm »
thankyou boss, it suppressed allot of the errors and leaves just this one;


Code: [Select]
error 008: must be a constant expression; assumed zero

Offline Boss

  • VC:MP Beta Tester (inactive)
  • Made Man
  • *
  • Posts: 229
  • Boss
    • View Profile
    • TDH Clan Site
Re: switch case help
« Reply #3 on: March 03, 2010, 05:01:20 pm »
Which exactly line gives that error?

It is usually thrown if you try to use variables outside of callbacks (e.g. specify array size with a variable).

Offline ramandu

  • Street Thug
  • *
  • Posts: 16
    • View Profile
Re: switch case help
« Reply #4 on: March 03, 2010, 05:13:24 pm »
hi, it points directly to this line

Code: [Select]
case "USER", "ADMIN", "HALF-ADMIN", "MODERATOR":

i am calling it like this,

Code: [Select]
if ( IsPlayerGroup_Mod("ramandu", "MODERATOR") ) { printf("yes, ramandu's group MODERATOR is found and also has access to user, admin, half-admin commands"); }

Offline Boss

  • VC:MP Beta Tester (inactive)
  • Made Man
  • *
  • Posts: 229
  • Boss
    • View Profile
    • TDH Clan Site
Re: switch case help
« Reply #5 on: March 03, 2010, 05:20:30 pm »
Why do you use Primary_Group[0]? It will switch only the first letter.
« Last Edit: March 03, 2010, 05:30:16 pm by Boss »

Offline ramandu

  • Street Thug
  • *
  • Posts: 16
    • View Profile
switch case help
« Reply #6 on: March 03, 2010, 05:27:33 pm »
hi, it seems the topic was locked for no apparent reason.

you asked me a question.

Why do you use Primary_Group
 its simply just name i gave it to represent the value of the function.

It will switch only the first letter.
ok thankyou for this information, how do i make it switch the complete word ?

Offline Boss

  • VC:MP Beta Tester (inactive)
  • Made Man
  • *
  • Posts: 229
  • Boss
    • View Profile
    • TDH Clan Site
Re: switch case help
« Reply #7 on: March 03, 2010, 05:31:55 pm »
hi, it seems the topic was locked for no apparent reason.
Might've been some bug, sorry.

ok thankyou for this information, how do i make it switch the complete word ?
Don't use [ 0 ] in switch. Just switch(Primary_Group).