Author Topic: How does this cause a Syntax Error?  (Read 590 times)

Code: [Select]
          function GameConnection::spawnPlayer(%client)
  {
                Parent::spawnPlayer(%client)
--switch(%client.score)--
{
case 2:
%item = akimbopistolItem.getID();
case 3:
%item = akimbopistolItem.getID();
case 4:
%item = machstilItem.getID();
case 5:
%item = machstilItem.getID();
case 6:
%item = magnumItem.getID();
case 7:
%item = magnumItem.getID();
case 8:
%item = pepperpistolItem.getID();
case 9:
%item = pepperpistolItem.getID();
case 10:
%item = combatshotgunItem.getID();
case 11:
%item = combatshotgunItem.getID();
case 12:
%item = huntingshotgunItem.getID();
case 13:
%item = huntingshotgunItem.getID();
case 14:
%item = pumpshotgunItem.getID();
case 15:
%item = pumpshotgunItem.getID();
case 16:
%item = microsmgItem.getID();
case 17:
%item = microsmgItem.getID();
case 18:
%item = submachinegunItem.getID();
case 19:
%item = submachinegunItem.getID();
case 20:
%item = battlerifleItem.getID();
case 21:
%item = battlerifleItem.getID();
case 22:
%item = bullpupItem.getID();
case 23:
%item = bullpupItem.getID();
case 24:
%item = militarysniperItem.getID();
case 25:
%item = militarysniperItem.getID();
case 26:
%item = tcrossbowItem.getID();
case 27:
%item = tcrossbowItem.getID();
case 28:
%item = rpgItem.getID();
case 29:
%item = rpgItem.getID();
case 30:
%item = tierfraggrenadeItem.getID();
case 31:
%item = tierfraggrenadeItem.getID();
}
%player = %client.player;
%slot = 0;
%oldTool = %player.tool[%slot];
%player.tool[%slot] = %item;
messageClient(%player,'MsgItemPickup','',%slot,%item);
}
Comes out with "Syntax Error on line 94!" which has the -- by it.

I don't understand how it comes out to a syntax error. And if there is any way to simplify the case stuff, then please tell me.

I would just stuff the data into an array.
(note it's been a while since I've done this so I might be forgetting something, but you get the general idea)
Code: [Select]
function define_item_array(){
   $item_array_set=1;
   $item_array_start = 2;
   $item_array[2] = akimbopistolitem.getID();
   $item_array[3] = akimbopistolitem.getID();
   $item_array[4] = machstil.getID();
   //etc
}

etc

then
Code: [Select]
if(!$item_array_set){
   define_item_array();
}
if(%client.score >= $item_array_start){
   %item = $item_array[%client.score];
}
to replace the switch.

However I don't know what your switch issue is, exactly.

Code: [Select]
Parent::spawnPlayer(%client)This needs a semi-colon.

Code: [Select]
Parent::spawnPlayer(%client)This needs a semi-colon.

Of course I skip over that. =/ Thanks.

I would just stuff the data into an array.
(note it's been a while since I've done this so I might be forgetting something, but you get the general idea)
Code: [Select]
function define_item_array(){
   $item_array_set=1;
   $item_array_start = 2;
   $item_array[2] = akimbopistolitem.getID();
   $item_array[3] = akimbopistolitem.getID();
   $item_array[4] = machstil.getID();
   //etc
}

etc

then
Code: [Select]
if(!$item_array_set){
   define_item_array();
}
if(%client.score >= $item_array_start){
   %item = $item_array[%client.score];
}
to replace the switch.

However I don't know what your switch issue is, exactly.
I kinda get the jist of it. I'll experiement more with that. Thank you.