Author Topic: Bad code  (Read 900 times)

0 Members and 1 Guest are viewing this topic.

Offline RunMan

  • Major(1)
  • Posts: 27
Bad code
« on: April 03, 2008, 02:09:46 pm »
What's wrong with this code?
Code: [Select]
procedure OnPlayerSpeak(ID: byte; Text: string);

begin

case Text of
!info:
begin
WriteConsole(ID,'List of avaliable commands/Lista dostepnych komend:',$00FF0000);
    WriteConsole(ID,'!admin - Shows list of admins / Pokazuje liste adminow',$00FF0000);
    WriteConsole(ID,'!ip - Shows your IP / Pokazuje Twoje IP',$00FF0000);
    WriteConsole(ID,'!ping - Shows your ping / Pokazuje Twoj ping',$00FF0000);
    WriteConsole(ID,'!nextmap - Shows the name of next map / Pokazuje nazwe nastepnej mapy', $00FF0000);
end;
!admin:
begin
WriteConsole(ID,'Admin: RunMan',$00FF0000);
end;
!ip:
begin
WriteConsole(ID,'Your IP is: / Twoje IP to: ' + IDToIP(ID),$00FF0000);
end;
!nextmap:
begin
if Text = !nextmap' then
    WriteConsole(ID,'The next map is: / Nastepna mapa to: ' + NextMap,$00FF0000);
end;
end;
Syntax error [7:1]

Date Posted: April 03, 2008, 02:29:50 pm
I forgot to put commands into '.
Now it shows <24:10> Identifier expected

Offline Aquarius

  • Soldier
  • **
  • Posts: 234
Re: Bad code
« Reply #1 on: April 03, 2008, 02:31:57 pm »
if Text = !nextmap' then

You forgot apostrophe


Hint: 24 is the line number and 10 is the column. It's very easy to find error this way.

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: Bad code
« Reply #2 on: April 03, 2008, 02:42:04 pm »
I forgot to put commands into '.
Now it shows <24:10> Identifier expected
seems like you're also missing one of those little things in if Text = !nextmap' then (should be if Text = '!nextmap' then)

Offline chrisgbk

  • Moderator
  • Veteran
  • *****
  • Posts: 1739
Re: Bad code
« Reply #3 on: April 03, 2008, 08:20:03 pm »
I may be mistaken, but you can't use CASE with non-ordinal types. This isn't visual basic.

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Bad code
« Reply #4 on: April 04, 2008, 07:06:01 am »
I think your wrong, Chris. This works for me:
Code: [Select]
procedure OnPlayerSpeak(ID: byte; Text: string);
begin
  Text := lowercase(Text)
  case Text of
    '!commands' : ShowCommands(ID);
    '!command' : ShowCommands(ID);
    '!adminonline' : AdminOnline(ID);
    '!admin' : ReqAdmin(ID);
    '!rate' :ShowRate(ID);
    '!ping' :ShowPing(ID);
    '!balance' : ForceBalance(ID);
    '!time' : WriteConsole (ID, 'The time is ' +FormatDate('hh:mm:ss am/pm'), cPersonal);
    '!myip' : WriteConsole(ID, 'Your IP is '+GetPlayerStat(ID, 'Ping'), cPersonal);
    '!nextmap' : StartVoteMap(ID, NextMap);
    //'!spec' : Command('/setteam5 ' + inttostr(ID));
    //'!joina' : Command('/setteam1 ' + inttostr(ID));
    //'!joinb' : Command('/setteam2 ' + inttostr(ID));
    else if (ContainsString(Text, '!rule')) then ShowRules(ID, Text);
  end;
end;
Come join: EliteCTF
Listen to: My Music