Author Topic: [solved]Syntax error when using Case ... of on arrays  (Read 984 times)

0 Members and 1 Guest are viewing this topic.

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
[solved]Syntax error when using Case ... of on arrays
« on: August 12, 2011, 06:40:37 pm »
title says it all, why is this happening? is there a particular way to use Case of on an array?

the uncommented part of the code is where the error points

Code: (pascal) [Select]
procedure OnPlayerKill(Killer, Victim: byte; Weapon: string);
begin
  Case Playerinfo[Killer].kills of
  {50 : begin
    SetRank(Killer, 'Private', 'Player', 1);
    WriteConsole(0,'Looks like this one might stay',$EE81FAA1);
    WriteConsole(0,'Please make our newest Player feel welcome',$EE81FAA1);
  end;
 
  if (PlayerInfo[Killer].lvl1learned = False) AND (PlayerInfo[Killer].Kills >= 50) AND (playerinfo[Killer].defskill = '') then begin
    Writeconsole(KIller,'congrats on your level',ClGood);
    WriteConsole(KIller,'you can now learn one of the following Defense skills/Perks:',ClGood);
    //Writeconsole(Killer,'/learn martyrdom - drops all of your remaining grenades live on death (perk)',ClGood);
    WriteConsole(Killer,'/learn kerbam - 10 percent chance of a tactic nuke on death (perk)',ClGood);
    //WriteConsole(Killer,'/learn shield - become invincable for 10 seconds (skill)',ClGood);
    WriteConsole(KIller,'100 kills for every 1 charge of the shield, "/use shield" to use 1 charge',ClGood);
    Writeconsole(Killer,'these messages will appear each kill until you select a skill/perk',ClBad);
  end;
 
  200 : SetRank(Killer, 'Corporal', 'Player', 2);
 
  500 : SetRank(Killer, 'Sergeant', 'Player', 3);

  1000 : begin
    SetRank(Killer, 'Captain', 'Officer', 4);
    WriteConsole(Killer,'Welcome to the ranks Rookie, great to have you with us',$EE81FAA1);
    WriteConsole(0,'Please welcome our newest Officer',$EE81FAA1);
  end;
 
  3000 : SetRank(Killer, 'Major', 'Officer', 5);

  4500 : SetRank(Killer, 'Colonel', 'Officer', 6);

  6000 : SetRank(Killer, 'General', 'Officer', 7);

  10000 : begin
    SetRank(Killer, 'Knight', 'Noble', 8);
    WriteConsole(0,'Please welcome our newest Noble',$EE81FAA1);
  end;
 
  20000 : begin
    SetRank(Killer, 'Baron', 'Elite', 9);
    WriteConsole(0,'We have an Elite on the field, welcome to the Vet Ranks '+idtoname(Killer)+'!',$EE81FAA1);
  end;
 
  50000 : SetRank(Killer, 'Earl', 'Elite', 10);

  75000 : SetRank(Killer, 'Duke', 'Dealer of Zombie Death', 11);

  100000 : begin
    SetRank(Killer, 'Warlord', 'FSG Veteran', 12);
    WriteConsole(0,GetPlayerStat(Killer, 'Name')+' Truly is an FSG Veteran',$EE81FAA1);
  end;}
 end;
end;

heres the full code for verififcation
http://pastebin.com/GnpcXEYy
« Last Edit: August 12, 2011, 07:56:46 pm by frosty »
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline ExHunter

  • Inactive Soldat Developer
  • Soldier
  • ******
  • Posts: 154
  • Speedy go!
Re: Syntax error when using Case ... of on arrays
« Reply #1 on: August 12, 2011, 07:02:47 pm »
Because u use { } ?

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: Syntax error when using Case ... of on arrays
« Reply #2 on: August 12, 2011, 07:07:14 pm »
no, {} is commenting, if i comment out that entire section, no error, if i remove the {} altogether, error is the same

ok lets just say we remove the {}, can anyone see whats causing the error?
Code: (pascal) [Select]
Case Playerinfo[Killer].kills of
  50 : begin
    SetRank(Killer, 'Private', 'Player', 1);
    WriteConsole(0,'Looks like this one might stay',$EE81FAA1);
    WriteConsole(0,'Please make our newest Player feel welcome',$EE81FAA1);
  end;
 
  if (PlayerInfo[Killer].lvl1learned = False) AND (PlayerInfo[Killer].Kills >= 50) AND (playerinfo[Killer].defskill = '') then begin
    Writeconsole(KIller,'congrats on your level',ClGood);
    WriteConsole(KIller,'you can now learn one of the following Defense skills/Perks:',ClGood);
    //Writeconsole(Killer,'/learn martyrdom - drops all of your remaining grenades live on death (perk)',ClGood);
    WriteConsole(Killer,'/learn kerbam - 10 percent chance of a tactic nuke on death (perk)',ClGood);
    //WriteConsole(Killer,'/learn shield - become invincable for 10 seconds (skill)',ClGood);
    //WriteConsole(KIller,'100 kills for every 1 charge of the shield, "/use shield" to use 1 charge',ClGood);
    Writeconsole(Killer,'these messages will appear each kill until you select a skill/perk',ClBad);
  end;
 
  200 : SetRank(Killer, 'Corporal', 'Player', 2);
 
  500 : SetRank(Killer, 'Sergeant', 'Player', 3);

  1000 : begin
    SetRank(Killer, 'Captain', 'Officer', 4);
    WriteConsole(Killer,'Welcome to the ranks Rookie, great to have you with us',$EE81FAA1);
    WriteConsole(0,'Please welcome our newest Officer',$EE81FAA1);
  end;
 
  3000 : SetRank(Killer, 'Major', 'Officer', 5);

  4500 : SetRank(Killer, 'Colonel', 'Officer', 6);

  6000 : SetRank(Killer, 'General', 'Officer', 7);

  10000 : begin
    SetRank(Killer, 'Knight', 'Noble', 8);
    WriteConsole(0,'Please welcome our newest Noble',$EE81FAA1);
  end;
 
  20000 : begin
    SetRank(Killer, 'Baron', 'Elite', 9);
    WriteConsole(0,'We have an Elite on the field, welcome to the Vet Ranks '+idtoname(Killer)+'!',$EE81FAA1);
  end;
 
  50000 : SetRank(Killer, 'Earl', 'Elite', 10);

  75000 : SetRank(Killer, 'Duke', 'Dealer of Zombie Death', 11);

  100000 : begin
    SetRank(Killer, 'Warlord', 'FSG Veteran', 12);
    WriteConsole(0,GetPlayerStat(Killer, 'Name')+' Truly is an FSG Veteran',$EE81FAA1);
  end;
  end;
« Last Edit: August 12, 2011, 07:11:22 pm by frosty »
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline ExHunter

  • Inactive Soldat Developer
  • Soldier
  • ******
  • Posts: 154
  • Speedy go!
Re: Syntax error when using Case ... of on arrays
« Reply #3 on: August 12, 2011, 07:14:27 pm »
Code: [Select]
if (PlayerInfo[Killer].lvl1learned = False) AND (PlayerInfo[Killer].Kills >= 50) AND (playerinfo[Killer].defskill = '') then begin 
   Writeconsole(KIller,'congrats on your level',ClGood); 
   WriteConsole(KIller,'you can now learn one of the following Defense skills/Perks:',ClGood); 
   //Writeconsole(Killer,'/learn martyrdom - drops all of your remaining grenades live on death (perk)',ClGood); 
   WriteConsole(Killer,'/learn kerbam - 10 percent chance of a tactic nuke on death (perk)',ClGood); 
   //WriteConsole(Killer,'/learn shield - become invincable for 10 seconds (skill)',ClGood); 
   //WriteConsole(KIller,'100 kills for every 1 charge of the shield, "/use shield" to use 1 charge',ClGood); 
   Writeconsole(Killer,'these messages will appear each kill until you select a skill/perk',ClBad); 
 end; 

i dont think that can be like that in a case function :P

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Syntax error when using Case ... of on arrays
« Reply #4 on: August 12, 2011, 07:37:54 pm »
As ExHunter said.

You have an if statement in the middle of a switch block, and not in a case block (not sure what the terms are really called in pascal (or in general); I probably butchered terms there :P).

Basically you have this:
Code: [Select]
case (foo) of

  50 : begin ... end;

  if(whatever) then begin ... end;

  200 : action();

end;
« Last Edit: August 12, 2011, 07:39:43 pm by DorkeyDear »

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: Syntax error when using Case ... of on arrays
« Reply #5 on: August 12, 2011, 07:56:25 pm »
Thanks, solved
check out my server! click here

If at first you don't succeed, Improvise! :D