Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-01

Compile time errors. Error: Duplicate identifier "Fragments" line 21 and AnsiStrings question.

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Pew piffle.the.cat

Hi Lazarus list,

I am updating some working code by rewriting some of the constant declarations. It is for a game called Awful Mint Things from Outer Space which is a free clone of Awful Green Things from Outer Space, and will be released under GNU GPL 3, around January or February.

Note that I am having trouble reading my Pascal text books as I have misplaced my reading glasses :-( !!!

I currently have 2 issues:
1) How do I define fragments_to_eggs_subrange which is an enumerated portion of green_types.
2) How do I define a constant array of strings //
string_stunned_the_green_message, etc

The constant array of string is needed for converting messages in my Lazarus application for cross language translation e.g. French, Spanish, Italian, Esperanto, etc.

I intend to use http://www.langtolang.com for the translations.

I think that I will modify my code to read an inifile then use TStringLists or similar and the LoadFromFile method. Will this work?!? I believe that I cannot use plain strings as these language use special symbols over the characters ?emluts? etc. How are these represented as strings or AnsiStrings?

unit test1;
{$mode objfpc}{$H+}
interface
uses
   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs;
type
   TForm1 = class(TForm)
   private
     { private declarations }
   public
     { public declarations }
   end;
type
   green_types = ( Fragments, Babies, Adults, Eggs, Group_of_Green_things );
// line 21
   fragments_to_eggs_subrange = (Fragments..Eggs) : green_types;
//                              ^^^^^^^^^
//test1.pas(21,42) Error: Duplicate identifier "Fragments"
//test1.pas(21,42) Hint: Identifier already defined in test1.pas at line 19
//test1.pas(21,42) Fatal: Syntax error, ")" expected but ".." foundunit
test1.pas

Hint: Start of reading config file /etc/fpc.cfg
Hint: End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 2.4.0-2 [2010/03/06] for i386 Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Linux for i386
Compiling testproject1.lpr
Compiling test1.pas
test1.pas(21,42) Error: Duplicate identifier "Fragments" test1.pas(21,42) Hint: Identifier already defined in test1.pas at line 19 test1.pas(21,42) Fatal: Syntax error, ")" expected but ".." foundunit test1.pas

   babies_to_eggs_subrange = (Babies..Eggs) : green_types;

green_things_type = record
present_count = array[
fragments_to_eggs_subrange ] of

                           integer;
                         stunned_count = array[

fragments_to_eggs_subrange ] of

                           integer;
                         new_count = array[ babies_to_eggs_subrange ] of
                           integer;
                       end;
var
   green_things : array[ room_subrange   ] of green_things_type;
procedure do_kill_stun( lower, upper : byte;
                         trying_to_stun : boolean;
                         j : integer );
type
   array_of_green_types_strings
     = array[ green_types ] : string;
   string_stunned_the_green_message
    = array_of_green_types_strings;
   string_killed_the_green_message
    = array_of_green_types_strings;
   string_no_longer_here_the_green_message
    = array_of_green_types_strings;
   string_survived_message
    = array_of_green_types_strings;

const
string_stunned_the_green_message
[ Fragments ] =

     ' stunned the Fragment';
   string_stunned_the_green_message
     [ Babies    ] =
     ' stunned the Baby';
   string_stunned_the_green_message
     [ Adults    ] =
     ' stunned the Adult';
   string_stunned_the_green_message
     [ Eggs      ] =
     ' stunned the Egg';
   string_stunned_the_green_message
     [ Group_of_Green_Things ] =
     ' stunned the Group of Green Things';
[snip]
var
   green,
   green_jj : green_types;
   k, count : byte;
   temp_green_count : array[ fragments_to_eggs_subrange ] of integer;
begin
   roll := random_in_range( lower, upper );
   if attacking_what = 'an Egg' then
     green_jj := Eggs
   else
     if attacking_what = 'a Baby' then
       green_jj := Babies
     else
       if attacking_what = 'a fragment' then
         green_jj := Fragments
       else
         if attacking_what = 'an Adult' then
           green_jj := Adults
         else { attacking a group }
           green_jj := Group_of_Green_things;
   end;
   info_form.SynMemo1.lines.add( 'The Egg''s constitution is: ' +
     inttostr( green_stats[ eggs ].constitution ) );
   info_form.SynMemo1.lines.add( 'He rolled a ' + inttostr( roll ) );
   temp_green_count[ green_jj ] := crew_data[ j
].green_data.present_count[ green_jj ];
  case green_jj of
     Fragments..Eggs :
       begin
         if roll >= green_stats[ green_jj ].constitution then
           begin
             if green_things[ attack_room_no ].present_count[ green_jj ]
0 then
               begin
                 dec( green_things[ attack_room_no ].present_count[
green_jj ] );
                 if trying_to_stun then
                   begin
                     inc( green_things[ attack_room_no ].stunned_count[
green_jj ] );
                     info_form.SynMemo1.lines.add( name + ' stunned the
Egg.');
                   end
                 else
                   info_form.SynMemo1.lines.add( name + ' killed the Egg.');
               end
             else
               info_form.SynMemo1.lines.add( 'There is no longer an Egg
here to attack.');
           end
           else
             info_form.SynMemo1.lines.add( 'The Egg survived the attack.');
       end;
[...]

Regards,
pew

Reply by email

Howard Page-Clark
to Pew piffle.the.cat
Pew wrote
Hi Lazarus list,

...

Show quoted text 5 lines
I currently have 2 issues: 1) How do I define fragments_to_eggs_subrange which is an enumerated portion of green_types. 2) How do I define a constant array of strings // string_stunned_the_green_message, etc

You want the following:

type
   green_types = ( Fragments, Babies, Adults, Eggs, Group_of_Green_things );
   fragments_to_eggs_subrange = Fragments..Eggs;
const
   GreenTypeStrings : array[green_types] of string =
     (' stunned the Fragment', ' stunned the Baby', ' stunned the Adult',
     ' stunned the Egg', ' stunned the Group of Green Things');

HTH

Howard

Reply by email

Pew piffle.the.cat
to Howard Page-Clark

Hi Howard,

This game was inspired by the 1968 movie "The Green Slime" http://www.imdb.com/title/tt0064393/

Howard Page-Clark wrote 8 lines
On 08/1/11 10:13, Pew (piffle.the.cat) wrote: > Hi Lazarus list, ... > I currently have 2 issues: > 1) How do I define fragments_to_eggs_subrange which is an enumerated > portion of green_types. > 2) How do I define a constant array of strings // > string_stunned_the_green_message, etc

Thank you. My pascal is a bit rusty and I have an excellent text book, however, I need to buy some new reading glasses. I will do that on Monday. :-)

Show quoted text 12 lines
You want the following: type green_types = ( Fragments, Babies, Adults, Eggs, Group_of_Green_things ); fragments_to_eggs_subrange = Fragments..Eggs; const GreenTypeStrings : array[green_types] of string = (' stunned the Fragment', ' stunned the Baby', ' stunned the Adult', ' stunned the Egg', ' stunned the Group of Green Things');
// not compiled yet

My next step is to change the const definition to variables so that I can define:

type
   languages = ( English, Italian, German, Spanish, Esperanto,
Simplified_Chinese, Japanese );
// I probably need to define the font name for each language also
// does anyone know the standard linux fonts for these languages???
   AnsiString_noun_of_green_message_2D_array =
     array[languages,green_types] of AnsiString;
// etc etc etc
   article_language_array = array[languages] of AnsiString;
   definitive_article_array = array[languages] of AnsiString;

var
AnsiString_noun_of_green_message

     : array[green_types] of AnsiString;

{
(' a Fragment', ' a Baby', ' an Adult',

     ' an Egg', ' The Group of Green Things');

}

type
   language_array_of_AnsiString = array[ languages ] of AnsiString;
   AnsiString_constitution_is : language_array_of_AnsiString; // = '
constitution is: '
   AnsiString_He_rolled_a : language_array_of_AnsiString; // = 'He
rolled a '
   AnsiString_stunned_the_green_message: language_array_of_AnsiString;
// = ' stunned '
   AnsiString_killed_the_green_message: language_array_of_AnsiString; //
= ' killed'
   AnsiString_There_is_no_longer: language_array_of_AnsiString; // =
'There is no longer'
   AnsiString_here_to_attack: language_array_of_AnsiString; // = ' here
to attack.'
   AnsiString_survived_the_attack: language_array_of_AnsiString; // = '
survived the attack.')
var
   AnsiString_There_is_no_longer : array[ languages ] of AnsiString;
   AnsiString_noun_of_green_things :array[ languages, green_jj ]of
AnsiString;
   AnsiString_here_to_attack :array[ languages ]of AnsiString;
// etc
   language : languages;
begin

{

Ask user for language preference
Open ini file and read file containing Ansi constants close ini file
read and assign AnsiStrings from text file to variables close text file

}
// code fragment
   info_form.SynMemo1.lines.add(
AnsiString_There_is_no_longer[ language ] +
AnsiString_noun_of_green_things[ language, green_jj ]+
      AnsiString_here_to_attack[ language ] );
// There is no longer a xxx here to attack. In the language of the user.
end;
var
   green,
   green_jj : green_types;
   k, count : byte;
   temp_green_count : array[ fragments_to_eggs_subrange ] of integer;
begin
   roll := random_in_range( lower, upper );
   if attacking_what =
     // an Egg
     article[language, 2]+' '+AnsiString_noun_of_green_message[Egg]then
       green_jj := Eggs
   else
     if attacking_what =
        // a Baby
article[language,1]+' '+AnsiString_noun_of_green_message[Babies]then
       green_jj := Babies
     else
       if attacking_what =
         // a Fragment
         article[language,1]+'
'+AnsiString_noun_of_green_message[Fragments]then
         green_jj := Fragments
       else
         if attacking_what =
            // an Adult
article[language,2]+' '+AnsiString_noun_of_green_message[Adults]then
           green_jj := Adults
         else { a group of Green Things }
           green_jj := Group_of_Green_things;
   end;
   info_form.SynMemo1.lines.add( definitive_article +
     //green_types = ( Fragments, Babies, Adults, Eggs,
Group_of_Green_things );
// e.g. The Egg's constitution is xxx
     // etc
     AnsiString_noun_of_green_message[ language, green_jj ] + ''' +
     AnsiString_constitution_is[ language ] +
     inttostr( green_stats[ eggs ].constitution ) );
   info_form.SynMemo1.lines.add( AnsiString_He_rolled_ a + inttostr(
roll ) );
   temp_green_count[ green_jj ] := crew_data[ j
].green_data.present_count[ green_jj ];
   if roll >= green_stats[ green_jj ].constitution then
   begin
     if green_things[ attack_room_no ].present_count[ green_jj ] > 0 then
        begin
          dec( green_things[ attack_room_no ].present_count[ green_jj ] );
          if trying_to_stun then
          begin
            inc( green_things[ attack_room_no ].stunned_count[ green_jj
] );
            info_form.SynMemo1.lines.add( name +
              AnsiString_stunned_the_green_message[ language ]+
              AnsiString_noun_of_green_things[ language, green_jj ]);
          end
          else
           info_form.SynMemo1.lines.add( name +
AnsiString_killed_the_green_message[ language ]+
               AnsiString_noun_of_green_things[ language, green_jj ]);
          end
     else
info_form.SynMemo1.lines.add(
AnsiString_There_is_no_longer[ language ] +
AnsiString_noun_of_green_things[ language, green_jj ]+
         AnsiString_here_to_attack[ language ] );
     end
   else
info_form.SynMemo1.lines.add(
AnsiString_noun_of_green_things[ green_jj ]+
         AnsiString_survived_the_attack[ language ] );
   end;
[...]

There are actually different arrays of strings for different states of action with the Green Things.

HTH Howard

Peter :-)))

pew

Show quoted text 5 lines
-- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Pew piffle.the.cat
to Howard Page-Clark: ... You want the following: type green_types = ( Fragments, Babies, Adults, Eggs,…

Hi Howard,

Howard Page-Clark wrote 8 lines
On 08/1/11 10:13, Pew (piffle.the.cat) wrote: > Hi Lazarus list, ... > I currently have 2 issues: > 1) How do I define fragments_to_eggs_subrange which is an enumerated > portion of green_types. > 2) How do I define a constant array of strings // > string_stunned_the_green_message, etc

Thank you. My pascal is a bit rusty and I have an excellent text book, however, I need to buy some new reading glasses. I will do that on Monday. :-)

Show quoted text 12 lines
You want the following: type green_types = ( Fragments, Babies, Adults, Eggs, Group_of_Green_things ); fragments_to_eggs_subrange = Fragments..Eggs; const GreenTypeStrings : array[green_types] of string = (' stunned the Fragment', ' stunned the Baby', ' stunned the Adult', ' stunned the Egg', ' stunned the Group of Green Things');
// not compiled yet
const
   article : array[1..2] of AnsiString = 'a', 'an';
   definitive_article = 'The ';
   AnsiString_noun_of_green_message
     : array[green_types] of AnsiString =
     (' Fragment', ' Baby', ' Adult',
     ' Egg', ' Group of Green Things');
   AnsiString_constitution_is = ' constitution is: ';
   AnsiString_He_rolled_a = 'He rolled a ';
   AnsiString_stunned_the_green_message = ' stunned ';
   AnsiString_killed_the_green_message = ' killed';
   AnsiString_There_is_no_longer = 'There is no longer';
   AnsiString_here_to_attack = ' here to attack.';
   AnsiString_survived_the_attack = ' survived the attack.');

My next step is to change the const definition to variables so that I can define:

type
   languages = ( English, Italian, German, Spanish, Esperanto,
Simplified_Chinese, Japanese );
// I probably need to define the font name for each language also
// does anyone know the standard linux fonts for these languages???
   article_language_array = array[languages] of AnsiString;
   definitive_article_array = array[languages] of AnsiString;
   AnsiString_noun_of_green_message_2D_array =
     array[languages,green_types] of AnsiString;
// etc etc etc
var
   article_language : article_language_array;
   definitive_article : definitive_article_array;
   AnsiString_There_is_no_longer : array[ languages ] of AnsiString;
   AnsiString_noun_of_green_things :array[ languages, green_jj ]of
AnsiString;
   AnsiString_here_to_attack :array[ languages ]of AnsiString;
   language : languages;
begin

{

Ask user for language preference
Open ini file and read file containing Ansi constants close ini file
read and assign AnsiStrings from text file to variables close text file

}

info_form.SynMemo1.lines.add(
AnsiString_There_is_no_longer[ language ] +
AnsiString_noun_of_green_things[ language, green_jj ]+

      AnsiString_here_to_attack[ language ] );
end;
var
   green,
   green_jj : green_types;
   k, count : byte;
   temp_green_count : array[ fragments_to_eggs_subrange ] of integer;
begin
   roll := random_in_range( lower, upper );
   if attacking_what =
     // an Egg
     article[language, 2]+' '+AnsiString_noun_of_green_message[Egg]then
       green_jj := Eggs
   else
     if attacking_what =
        // a Baby
article[language,1]+' '+AnsiString_noun_of_green_message[Babies]then
       green_jj := Babies
     else
       if attacking_what =
         // a Fragment
         article[language,1]+'
'+AnsiString_noun_of_green_message[Fragments]then
         green_jj := Fragments
       else
         if attacking_what =
            // an Adult
article[language,2]+' '+AnsiString_noun_of_green_message[Adults]then
           green_jj := Adults
         else { a group of Green Things }
           green_jj := Group_of_Green_things;
   end;
   info_form.SynMemo1.lines.add( definitive_article +
     //green_types = ( Fragments, Babies, Adults, Eggs,
Group_of_Green_things );
// e.g. The Egg's constitution is xxx
     // etc
     AnsiString_noun_of_green_message[ language, green_jj ] + ''' +
     AnsiString_constitution_is[ language ] +
     inttostr( green_stats[ eggs ].constitution ) );
   info_form.SynMemo1.lines.add( AnsiString_He_rolled_ a + inttostr(
roll ) );
   temp_green_count[ green_jj ] := crew_data[ j
].green_data.present_count[ green_jj ];
   if roll >= green_stats[ green_jj ].constitution then
   begin
     if green_things[ attack_room_no ].present_count[ green_jj ] > 0 then
        begin
          dec( green_things[ attack_room_no ].present_count[ green_jj ] );
          if trying_to_stun then
          begin
            inc( green_things[ attack_room_no ].stunned_count[ green_jj
] );
            info_form.SynMemo1.lines.add( name +
              AnsiString_stunned_the_green_message[ language ]+
              AnsiString_noun_of_green_things[ language, green_jj ]);
          end
          else
           info_form.SynMemo1.lines.add( name +
AnsiString_killed_the_green_message[ language ]+
               AnsiString_noun_of_green_things[ language, green_jj ]);
          end
     else
info_form.SynMemo1.lines.add(
AnsiString_There_is_no_longer[ language ] +
AnsiString_noun_of_green_things[ language, green_jj ]+
         AnsiString_here_to_attack[ language ] );
     end
   else
info_form.SynMemo1.lines.add(
AnsiString_definitive_article[ language ] +
AnsiString_noun_of_green_things[ green_jj ]+
         AnsiString_survived_the_attack[ language ] );
   end;
[...]

There are actually different arrays of strings for different states of action with the Green Things.

HTH Howard

Peter :-)))

pew

Show quoted text 5 lines
-- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email